From 7c2fc0f42be04711b3b34244c5ee87b7ebd286fb Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sun, 26 Feb 2023 01:20:59 -0800 Subject: [PATCH 1/6] Support setting refreshToken manually --- src/Token/AccessToken.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Token/AccessToken.php b/src/Token/AccessToken.php index 81533c30..9157f68e 100644 --- a/src/Token/AccessToken.php +++ b/src/Token/AccessToken.php @@ -169,6 +169,14 @@ public function getRefreshToken() return $this->refreshToken; } + /** + * @inheritdoc + */ + public function setRefreshToken($refreshToken) + { + $this->refreshToken = $refreshToken; + } + /** * @inheritdoc */ From 7819ab1e1c5e66ec9534ba2bb0405bdacd3f03d3 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sun, 26 Feb 2023 01:37:25 -0800 Subject: [PATCH 2/6] Add test --- test/src/Token/AccessTokenTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/src/Token/AccessTokenTest.php b/test/src/Token/AccessTokenTest.php index 23ad105f..17075a7a 100644 --- a/test/src/Token/AccessTokenTest.php +++ b/test/src/Token/AccessTokenTest.php @@ -123,6 +123,23 @@ public function testGetRefreshToken() self::tearDownForBackwardsCompatibility(); } + public function testSetRefreshToken() + { + $refreshToken = 'refresh_token'; + + $options = [ + 'access_token' => 'access_token', + ]; + + $token = $this->getAccessToken($options); + + $token->setRefreshToken($refreshToken); + + $this->assertEquals($refreshToken, $token->getRefreshToken()); + + self::tearDownForBackwardsCompatibility(); + } + public function testHasNotExpiredWhenPropertySetInFuture() { $options = [ From 057313111796326d88eb2898d6182bf211a397d4 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sun, 16 Apr 2023 11:44:18 -0700 Subject: [PATCH 3/6] Create SettableRefreshTokenInterface --- src/Token/AccessToken.php | 2 +- src/Token/SettableRefreshTokenInterface.php | 26 +++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/Token/SettableRefreshTokenInterface.php diff --git a/src/Token/AccessToken.php b/src/Token/AccessToken.php index 9157f68e..0f0206a4 100644 --- a/src/Token/AccessToken.php +++ b/src/Token/AccessToken.php @@ -22,7 +22,7 @@ * * @link http://tools.ietf.org/html/rfc6749#section-1.4 Access Token (RFC 6749, ยง1.4) */ -class AccessToken implements AccessTokenInterface, ResourceOwnerAccessTokenInterface +class AccessToken implements AccessTokenInterface, ResourceOwnerAccessTokenInterface, SettableRefreshTokenInterface { /** * @var string diff --git a/src/Token/SettableRefreshTokenInterface.php b/src/Token/SettableRefreshTokenInterface.php new file mode 100644 index 00000000..601e9540 --- /dev/null +++ b/src/Token/SettableRefreshTokenInterface.php @@ -0,0 +1,26 @@ + + * @license http://opensource.org/licenses/MIT MIT + * @link http://thephpleague.com/oauth2-client/ Documentation + * @link https://packagist.org/packages/league/oauth2-client Packagist + * @link https://github.com/thephpleague/oauth2-client GitHub + */ + +namespace League\OAuth2\Client\Token; + +interface SettableRefreshTokenInterface extends AccessTokenInterface +{ + /** + * Sets the refresh token. + * + * @param string $refreshToken + * @return void + */ + public function setRefreshToken($refreshToken); +} From c3e413a6dcdb04a9734debf9c2f8d1b3b5fb5335 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sun, 16 Apr 2023 11:46:57 -0700 Subject: [PATCH 4/6] Update doc copy --- src/Token/SettableRefreshTokenInterface.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Token/SettableRefreshTokenInterface.php b/src/Token/SettableRefreshTokenInterface.php index 601e9540..0a056685 100644 --- a/src/Token/SettableRefreshTokenInterface.php +++ b/src/Token/SettableRefreshTokenInterface.php @@ -17,9 +17,9 @@ interface SettableRefreshTokenInterface extends AccessTokenInterface { /** - * Sets the refresh token. + * Sets or replaces the refresh token with the provided refresh token. * - * @param string $refreshToken + * @param string $refreshToken * @return void */ public function setRefreshToken($refreshToken); From 35aae9c7b1daad11c4e2259fab611e08052fb0d8 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sun, 16 Apr 2023 11:51:05 -0700 Subject: [PATCH 5/6] Don't extend AccessTokenInterface --- src/Token/ResourceOwnerAccessTokenInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Token/ResourceOwnerAccessTokenInterface.php b/src/Token/ResourceOwnerAccessTokenInterface.php index 51e4ce41..36418fd8 100644 --- a/src/Token/ResourceOwnerAccessTokenInterface.php +++ b/src/Token/ResourceOwnerAccessTokenInterface.php @@ -14,7 +14,7 @@ namespace League\OAuth2\Client\Token; -interface ResourceOwnerAccessTokenInterface extends AccessTokenInterface +interface ResourceOwnerAccessTokenInterface { /** * Returns the resource owner identifier, if defined. From 49777e39da3ac7c863699d5572087840a51b1f95 Mon Sep 17 00:00:00 2001 From: Garrett Grimm Date: Sun, 16 Apr 2023 11:51:38 -0700 Subject: [PATCH 6/6] Don't extend AccessTokenInterface --- src/Token/ResourceOwnerAccessTokenInterface.php | 2 +- src/Token/SettableRefreshTokenInterface.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Token/ResourceOwnerAccessTokenInterface.php b/src/Token/ResourceOwnerAccessTokenInterface.php index 36418fd8..51e4ce41 100644 --- a/src/Token/ResourceOwnerAccessTokenInterface.php +++ b/src/Token/ResourceOwnerAccessTokenInterface.php @@ -14,7 +14,7 @@ namespace League\OAuth2\Client\Token; -interface ResourceOwnerAccessTokenInterface +interface ResourceOwnerAccessTokenInterface extends AccessTokenInterface { /** * Returns the resource owner identifier, if defined. diff --git a/src/Token/SettableRefreshTokenInterface.php b/src/Token/SettableRefreshTokenInterface.php index 0a056685..491bee99 100644 --- a/src/Token/SettableRefreshTokenInterface.php +++ b/src/Token/SettableRefreshTokenInterface.php @@ -14,7 +14,7 @@ namespace League\OAuth2\Client\Token; -interface SettableRefreshTokenInterface extends AccessTokenInterface +interface SettableRefreshTokenInterface { /** * Sets or replaces the refresh token with the provided refresh token.