Skip to content

Commit

Permalink
Support setting refreshToken (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
grimmdude authored Apr 16, 2023
1 parent b072900 commit 5b64ba6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/Token/AccessToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -169,6 +169,14 @@ public function getRefreshToken()
return $this->refreshToken;
}

/**
* @inheritdoc
*/
public function setRefreshToken($refreshToken)
{
$this->refreshToken = $refreshToken;
}

/**
* @inheritdoc
*/
Expand Down
26 changes: 26 additions & 0 deletions src/Token/SettableRefreshTokenInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* This file is part of the league/oauth2-client library
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*
* @copyright Copyright (c) Alex Bilbie <[email protected]>
* @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);
}
17 changes: 17 additions & 0 deletions test/src/Token/AccessTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit 5b64ba6

Please sign in to comment.