Skip to content

OAuth: Support tenant_name Parameter #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading