Created
November 13, 2021 17:12
-
-
Save justingreerbbi/e516e4f552ca12de867c7de6ef966bbe to your computer and use it in GitHub Desktop.
Increase access token after successful use but X minutes. This is for WordPress OAuth Server. Place this snippet into your themes functions.php file. It taps into the authenticated action WP OAuth Server uses when checking authorization of a call.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* UPDATES AN ACCESS TOKEN'S EXPIRE TIME BY X AMOUNT OF TIME WHEN SUCCESSFULLY USED FOR AUTHENTICATION | |
* | |
* NOTE: This will override any token settings used within the plugin but does allow for active tokens to | |
* stay active instead of expiring. This is useful for auto deauthentication tht is traditionally handled on the | |
* client side. | |
*/ | |
add_action( 'wo_endpoint_user_authenticated', 'wp_oauth_successful_authentication_action' ); | |
function wp_oauth_successful_authentication_action( $token ) { | |
//$current_expires = $token[0]['expires']; | |
$access_token = $token[0]['access_token']; | |
$minutes = 30; | |
$new_expires = date( 'Y-m-d H:i:s', current_time( 'timestamp' ) + ( $minutes * 60 ) ); | |
global $wpdb; | |
$update = $wpdb->update( $wpdb->prefix . 'oauth_access_tokens', array( | |
'expires' => $new_expires | |
), array( 'access_token' => $access_token ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment