mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 09:08:09 +08:00
Invalidate cache when switching user
This commit is contained in:
parent
22c2b5afd4
commit
a1413782e9
2 changed files with 26 additions and 4 deletions
|
@ -83,7 +83,12 @@ class SdkClientToken {
|
|||
*/
|
||||
public function sdk_client_token( string $target_customer_id = '' ): string {
|
||||
if ( $this->cache->has( self::CACHE_KEY ) ) {
|
||||
return $this->cache->get( self::CACHE_KEY );
|
||||
$user_id = $this->cache->get( self::CACHE_KEY )['user_id'] ?? 0;
|
||||
$access_token = $this->cache->get( self::CACHE_KEY )['access_token'] ?? '';
|
||||
|
||||
if ( $user_id === get_current_user_id() && $access_token ) {
|
||||
return $access_token;
|
||||
}
|
||||
}
|
||||
|
||||
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
|
@ -121,7 +126,13 @@ class SdkClientToken {
|
|||
}
|
||||
|
||||
$access_token = $json->access_token;
|
||||
$this->cache->set( self::CACHE_KEY, $access_token );
|
||||
|
||||
$data = array(
|
||||
'access_token' => $access_token,
|
||||
'user_id' => get_current_user_id(),
|
||||
);
|
||||
|
||||
$this->cache->set( self::CACHE_KEY, $data );
|
||||
|
||||
return $access_token;
|
||||
}
|
||||
|
|
|
@ -83,7 +83,12 @@ class UserIdToken {
|
|||
*/
|
||||
public function id_token( string $target_customer_id = '' ): string {
|
||||
if ( $this->cache->has( self::CACHE_KEY ) ) {
|
||||
return $this->cache->get( self::CACHE_KEY );
|
||||
$user_id = $this->cache->get( self::CACHE_KEY )['user_id'] ?? 0;
|
||||
$id_token = $this->cache->get( self::CACHE_KEY )['id_token'] ?? '';
|
||||
|
||||
if ( $user_id === get_current_user_id() && $id_token ) {
|
||||
return $id_token;
|
||||
}
|
||||
}
|
||||
|
||||
$url = trailingslashit( $this->host ) . 'v1/oauth2/token?grant_type=client_credentials&response_type=id_token';
|
||||
|
@ -116,7 +121,13 @@ class UserIdToken {
|
|||
}
|
||||
|
||||
$id_token = $json->id_token;
|
||||
$this->cache->set( self::CACHE_KEY, $id_token );
|
||||
|
||||
$data = array(
|
||||
'id_token' => $id_token,
|
||||
'user_id' => get_current_user_id(),
|
||||
);
|
||||
|
||||
$this->cache->set( self::CACHE_KEY, $data );
|
||||
|
||||
return $id_token;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue