Skip to content

Commit 275a38e

Browse files
authored
Merge pull request #14 from wp-graphql/bug/#13-tokens-are-identical
#13 - tokens are identical
2 parents 3e62781 + 51478db commit 275a38e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Auth.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,14 +297,16 @@ public static function get_token( $user, $cap_check = true ) {
297297

298298
public static function get_refresh_token( $user, $cap_check = true ) {
299299

300+
self::$is_refresh_token = true;
301+
300302
/**
301303
* Filter the token signature for refresh tokens, adding the user_secret to the signature and making the
302304
* expiration long lived so that the token can be used for a long time without the client having to store a new
303305
* one.
304306
*/
305307
add_filter( 'graphql_jwt_auth_token_before_sign', function( $token, \WP_User $user ) {
306308
$secret = Auth::get_user_jwt_secret( $user->ID );
307-
if ( ! empty( $secret ) && ! is_wp_error( $secret ) ) {
309+
if ( ! empty( $secret ) && ! is_wp_error( $secret ) && true === self::is_refresh_token() ) {
308310

309311
/**
310312
* Set the expiration date as a year from now to make the refresh token long lived, allowing the
@@ -313,6 +315,9 @@ public static function get_refresh_token( $user, $cap_check = true ) {
313315
*/
314316
$token['exp'] = apply_filters( 'graphql_jwt_auth_refresh_token_expiration', ( self::get_token_issued() + ( DAY_IN_SECONDS * 365 ) ) );
315317
$token['data']['user']['user_secret'] = $secret;
318+
319+
self::$is_refresh_token = false;
320+
316321
}
317322

318323
return $token;

0 commit comments

Comments
 (0)