diff --git a/src/Token/AccessToken.php b/src/Token/AccessToken.php index 81533c30..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 @@ -169,6 +169,14 @@ public function getRefreshToken() return $this->refreshToken; } + /** + * @inheritdoc + */ + public function setRefreshToken($refreshToken) + { + $this->refreshToken = $refreshToken; + } + /** * @inheritdoc */ diff --git a/src/Token/SettableRefreshTokenInterface.php b/src/Token/SettableRefreshTokenInterface.php new file mode 100644 index 00000000..491bee99 --- /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 +{ + /** + * Sets or replaces the refresh token with the provided refresh token. + * + * @param string $refreshToken + * @return void + */ + public function setRefreshToken($refreshToken); +} 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 = [