Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support setting refreshToken #994

Merged
merged 8 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
grimmdude marked this conversation as resolved.
Show resolved Hide resolved
{
$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