Cheetah
RefreshToken.php
Go to the documentation of this file.
1 <?php
2 
3 namespace OAuth2\GrantType;
4 
9 
15 {
16  private $refreshToken;
17 
18  protected $storage;
19  protected $config;
20 
31  public function __construct(RefreshTokenInterface $storage, $config = array())
32  {
33  $this->config = array_merge(array(
34  'always_issue_new_refresh_token' => false,
35  'unset_refresh_token_after_use' => true
36  ), $config);
37 
38  // to preserve B.C. with v1.6
39  // @see https://github.com/bshaffer/oauth2-server-php/pull/580
40  // @todo - remove in v2.0
41  if (isset($config['always_issue_new_refresh_token']) && !isset($config['unset_refresh_token_after_use'])) {
42  $this->config['unset_refresh_token_after_use'] = $config['always_issue_new_refresh_token'];
43  }
44 
45  $this->storage = $storage;
46  }
47 
48  public function getQuerystringIdentifier()
49  {
50  return 'refresh_token';
51  }
52 
53  public function validateRequest(RequestInterface $request, ResponseInterface $response)
54  {
55  if (!$request->request("refresh_token")) {
56  $response->setError(400, 'invalid_request', 'Missing parameter: "refresh_token" is required');
57 
58  return null;
59  }
60 
61  if (!$refreshToken = $this->storage->getRefreshToken($request->request("refresh_token"))) {
62  $response->setError(400, 'invalid_grant', 'Invalid refresh token');
63 
64  return null;
65  }
66 
67  if ($refreshToken['expires'] > 0 && $refreshToken["expires"] < time()) {
68  $response->setError(400, 'invalid_grant', 'Refresh token has expired');
69 
70  return null;
71  }
72 
73  // store the refresh token locally so we can delete it when a new refresh token is generated
74  $this->refreshToken = $refreshToken;
75 
76  return true;
77  }
78 
79  public function getClientId()
80  {
81  return $this->refreshToken['client_id'];
82  }
83 
84  public function getUserId()
85  {
86  return isset($this->refreshToken['user_id']) ? $this->refreshToken['user_id'] : null;
87  }
88 
89  public function getScope()
90  {
91  return isset($this->refreshToken['scope']) ? $this->refreshToken['scope'] : null;
92  }
93 
94  public function createAccessToken(AccessTokenInterface $accessToken, $client_id, $user_id, $scope)
95  {
96  /*
97  * It is optional to force a new refresh token when a refresh token is used.
98  * However, if a new refresh token is issued, the old one MUST be expired
99  * @see http://tools.ietf.org/html/rfc6749#section-6
100  */
101  $issueNewRefreshToken = $this->config['always_issue_new_refresh_token'];
102  $unsetRefreshToken = $this->config['unset_refresh_token_after_use'];
103  $token = $accessToken->createAccessToken($client_id, $user_id, $scope, $issueNewRefreshToken);
104 
105  if ($unsetRefreshToken) {
106  $this->storage->unsetRefreshToken($this->refreshToken['refresh_token']);
107  }
108 
109  return $token;
110  }
111 }
OAuth2\GrantType\GrantTypeInterface
Definition: GrantTypeInterface.php:13
OAuth2\GrantType\RefreshToken\createAccessToken
createAccessToken(AccessTokenInterface $accessToken, $client_id, $user_id, $scope)
Definition: RefreshToken.php:94
OAuth2\RequestInterface\request
request($name, $default=null)
use
GNU LESSER GENERAL PUBLIC LICENSE February Free Software Inc Franklin Fifth MA USA Everyone is permitted to copy and distribute verbatim copies of this license but changing it is not allowed[This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it By the GNU General Public Licenses are intended to guarantee your freedom to share and change free software to make sure the software is free for all its users This the Lesser General Public applies to some specially designated software packages typically libraries of the Free Software Foundation and other authors who decide to use it You can use it but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular based on the explanations below When we speak of free we are referring to freedom of use
Definition: license.txt:27
OAuth2\GrantType
Definition: AuthorizationCode.php:3
php
OAuth2\GrantType\RefreshToken\getUserId
getUserId()
Definition: RefreshToken.php:84
OAuth2\ResponseType\AccessTokenInterface
Definition: AccessTokenInterface.php:10
OAuth2\ResponseInterface\setError
setError($statusCode, $name, $description=null, $uri=null)
OAuth2\GrantType\RefreshToken\__construct
__construct(RefreshTokenInterface $storage, $config=array())
Definition: RefreshToken.php:31
OAuth2\GrantType\RefreshToken
Definition: RefreshToken.php:15
OAuth2\GrantType\RefreshToken\validateRequest
validateRequest(RequestInterface $request, ResponseInterface $response)
Definition: RefreshToken.php:53
OAuth2\GrantType\RefreshToken\getQuerystringIdentifier
getQuerystringIdentifier()
Definition: RefreshToken.php:48
time
that in the case of a Adaptation or at a minimum such credit will if a credit for all contributing authors of the Adaptation or Collection then as part of these credits and in a manner at least as prominent as the credits for the other contributing authors For the avoidance of You may only use the credit required by this Section for the purpose of attribution in the manner set out above by exercising Your rights under this You may not implicitly or explicitly assert or imply any connection sponsorship or endorsement by the Original Licensor and or Attribution as of You or Your use of the without the express prior written permission of the Original Licensor and or Attribution Parties Except as otherwise agreed in writing by the Licensor or as may be otherwise permitted by applicable if You Distribute or Publicly Perform the Work either by itself or as part of any Adaptations or You must not modify or take other derogatory action in relation to the Work which would be prejudicial to the Original Author s honor or reputation Licensor agrees that in those in which any exercise of the right granted in modification or other derogatory action prejudicial to the Original Author s honor and the Licensor will waive or not as this to the fullest extent permitted by the applicable national to enable You to reasonably exercise Your right under Warranties and Disclaimer UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN LICENSOR OFFERS THE WORK AS IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND CONCERNING THE STATUTORY OR WITHOUT WARRANTIES OF FITNESS FOR A PARTICULAR OR THE ABSENCE OF LATENT OR OTHER OR THE PRESENCE OF ABSENCE OF WHETHER OR NOT DISCOVERABLE SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OF IMPLIED SO SUCH EXCLUSION MAY NOT APPLY TO YOU Limitation on Liability EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR ANY PUNITIVE OR EXEMPLARY DAMAGES ARISING OUT OF THIS LICENSE OR THE USE OF THE EVEN IF LICENSOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES Termination This License and the rights granted hereunder will terminate automatically upon any breach by You of the terms of this License Individuals or entities who have received Adaptations or Collections from You under this will not have their licenses terminated provided such individuals or entities remain in full compliance with those licenses and will survive any termination of this License Subject to the above terms and the license granted here is Licensor reserves the right to release the Work under different license terms or to stop distributing the Work at any time
Definition: license.txt:56
OAuth2\ResponseInterface
Definition: ResponseInterface.php:12
OAuth2\GrantType\RefreshToken\getScope
getScope()
Definition: RefreshToken.php:89
OAuth2\ResponseType\AccessTokenInterface\createAccessToken
createAccessToken($client_id, $user_id, $scope=null, $includeRefreshToken=true)
OAuth2\Storage\RefreshTokenInterface
Definition: RefreshTokenInterface.php:13
OAuth2\GrantType\RefreshToken\$storage
$storage
Definition: RefreshToken.php:18
OAuth2\RequestInterface
Definition: RequestInterface.php:6
OAuth2\GrantType\RefreshToken\$config
$config
Definition: RefreshToken.php:19
OAuth2\GrantType\RefreshToken\getClientId
getClientId()
Definition: RefreshToken.php:79