-
Notifications
You must be signed in to change notification settings - Fork 8
Revoke and Remove Tokens on Disconnect #1064
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
base: main
Are you sure you want to change the base?
Changes from all commits
c3e11bd
392ad17
01548e5
c08776b
4e0c10a
d927482
3595841
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,7 @@ | |
| "type": "project", | ||
| "license": "GPLv3", | ||
| "require": { | ||
| "convertkit/convertkit-wordpress-libraries": "2.1.3" | ||
| "convertkit/convertkit-wordpress-libraries": "dev-add-revoke-token-method" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know anything about WP so just double-checking we want this and it wasn't accidentally left in from testing |
||
| }, | ||
| "require-dev": { | ||
| "php-webdriver/webdriver": "^1.0", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -792,6 +792,29 @@ function convertkit_maybe_update_credentials( $result, $client_id ) { | |
|
|
||
| } | ||
|
|
||
| /** | ||
| * Deletes the stored access token, refresh token and its expiry from the Plugin settings, | ||
| * and clears any existing scheduled WordPress Cron event to refresh the token on expiry, | ||
| * when the user revokes the access token. | ||
| * | ||
| * @since 3.2.4 | ||
| * | ||
| * @param string $client_id OAuth Client ID used for the Access and Refresh Tokens. | ||
| */ | ||
| function convertkit_delete_credentials( $client_id ) { | ||
|
|
||
| // Don't delete these credentials if they're not for this Client ID. | ||
| // They're for another Kit Plugin that uses OAuth. | ||
| if ( $client_id !== CONVERTKIT_OAUTH_CLIENT_ID ) { | ||
| return; | ||
| } | ||
|
|
||
| // Delete Access and Refresh Tokens. | ||
| $settings = new ConvertKit_Settings(); | ||
| $settings->delete_credentials(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this delete all the keys such as CONVERTKIT_API_KEY? Are we storing those in the WordPress plugin?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated |
||
|
|
||
| } | ||
|
|
||
| /** | ||
| * Deletes the stored access token, refresh token and its expiry from the Plugin settings, | ||
| * and clears any existing scheduled WordPress Cron event to refresh the token on expiry, | ||
|
|
@@ -830,6 +853,9 @@ function convertkit_maybe_delete_credentials( $result, $client_id ) { | |
| add_action( 'convertkit_api_get_access_token', 'convertkit_maybe_update_credentials', 10, 2 ); | ||
| add_action( 'convertkit_api_refresh_token', 'convertkit_maybe_update_credentials', 10, 2 ); | ||
|
|
||
| // Delete credentials when the user revokes the access and refresh tokens. | ||
| add_action( 'convertkit_api_revoke_tokens', 'convertkit_delete_credentials', 10, 1 ); | ||
|
|
||
| // Delete credentials if the API class uses a invalid access token. | ||
| // This prevents the Plugin making repetitive API requests that will 401. | ||
| add_action( 'convertkit_api_access_token_invalid', 'convertkit_maybe_delete_credentials', 10, 2 ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice error message, thank you!