Skip to content

Commit

Permalink
Add support for tenant_name parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
n7studios committed Nov 8, 2024
1 parent 345b74c commit 064a035
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/class-convertkit-api-v4.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,11 @@ public function base64_urlencode( $str ) {
*
* @since 2.0.0
*
* @param bool|string $return_url Return URL.
* @return string OAuth URL
* @param bool|string $return_url Return URL.
* @param bool|string $tenant_name Tenant Name (if specified, issues tokens specific to that name. Useful for using the same account on multiple sites).
* @return string OAuth URL
*/
public function get_oauth_url( $return_url = false ) {
public function get_oauth_url( $return_url = false, $tenant_name = false ) {

// Generate and store code verifier and challenge.
$code_verifier = $this->generate_and_store_code_verifier();
Expand All @@ -368,6 +369,10 @@ public function get_oauth_url( $return_url = false ) {
);
}

if ( $tenant_name ) {
$args['tenant_name'] = rawurlencode( $tenant_name );
}

// Return OAuth URL.
return add_query_arg(
$args,
Expand Down
26 changes: 26 additions & 0 deletions tests/wpunit/APITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,32 @@ public function testGetOAuthURLWithState()
);
}

/**
* Test that get_oauth_url() returns the correct URL to begin the OAuth process
* when a tenant_name parameter is supplied.
*
* @since 2.0.5
*
* @return void
*/
public function testGetOAuthURLWithTenantName()
{
// Confirm the OAuth URL returned is correct.
$this->assertEquals(
$this->api->get_oauth_url( false, 'https://example.com' ),
'https://app.kit.com/oauth/authorize?' . http_build_query(
[
'client_id' => $_ENV['CONVERTKIT_OAUTH_CLIENT_ID'],
'response_type' => 'code',
'redirect_uri' => $_ENV['CONVERTKIT_OAUTH_REDIRECT_URI'],
'code_challenge' => $this->api->generate_code_challenge( $this->api->get_code_verifier() ),
'code_challenge_method' => 'S256',
'tenant_name' => 'https://example.com',
]
)
);
}

/**
* Test that get_access_token() returns the expected data.
*
Expand Down

0 comments on commit 064a035

Please sign in to comment.