mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-01-09 05:23:53 +05:30
Changed method names to be clearer that we're setting params
This commit is contained in:
parent
1e3a192920
commit
a3f5d20592
@ -230,15 +230,15 @@ class AuthCodeGrant extends AbstractGrant
|
|||||||
$accessToken->associateScope($scope);
|
$accessToken->associateScope($scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getTokenType()->set('access_token', $accessToken->getId());
|
$this->server->getTokenType()->setParam('access_token', $accessToken->getId());
|
||||||
$this->server->getTokenType()->set('expires_in', $this->getAccessTokenTTL());
|
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
|
||||||
|
|
||||||
// Associate a refresh token if set
|
// Associate a refresh token if set
|
||||||
if ($this->server->hasGrantType('refresh_token')) {
|
if ($this->server->hasGrantType('refresh_token')) {
|
||||||
$refreshToken = new RefreshTokenEntity($this->server);
|
$refreshToken = new RefreshTokenEntity($this->server);
|
||||||
$refreshToken->setId(SecureKey::generate());
|
$refreshToken->setId(SecureKey::generate());
|
||||||
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
||||||
$this->server->getTokenType()->set('refresh_token', $refreshToken->getId());
|
$this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Expire the auth code
|
// Expire the auth code
|
||||||
|
@ -112,8 +112,8 @@ class ClientCredentialsGrant extends AbstractGrant
|
|||||||
$accessToken->setSession($session);
|
$accessToken->setSession($session);
|
||||||
$accessToken->save($this->server->getStorage('access_token'));
|
$accessToken->save($this->server->getStorage('access_token'));
|
||||||
|
|
||||||
$this->server->getTokenType()->set('access_token', $accessToken->getId());
|
$this->server->getTokenType()->setParam('access_token', $accessToken->getId());
|
||||||
$this->server->getTokenType()->set('expires_in', $this->getAccessTokenTTL());
|
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
|
||||||
|
|
||||||
return $this->server->getTokenType()->generateResponse();
|
return $this->server->getTokenType()->generateResponse();
|
||||||
}
|
}
|
||||||
|
@ -148,15 +148,15 @@ class PasswordGrant extends AbstractGrant
|
|||||||
$accessToken->associateScope($scope);
|
$accessToken->associateScope($scope);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getTokenType()->set('access_token', $accessToken->getId());
|
$this->server->getTokenType()->setParam('access_token', $accessToken->getId());
|
||||||
$this->server->getTokenType()->set('expires_in', $this->getAccessTokenTTL());
|
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
|
||||||
|
|
||||||
// Associate a refresh token if set
|
// Associate a refresh token if set
|
||||||
if ($this->server->hasGrantType('refresh_token')) {
|
if ($this->server->hasGrantType('refresh_token')) {
|
||||||
$refreshToken = new RefreshTokenEntity($this->server);
|
$refreshToken = new RefreshTokenEntity($this->server);
|
||||||
$refreshToken->setId(SecureKey::generate());
|
$refreshToken->setId(SecureKey::generate());
|
||||||
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
$refreshToken->setExpireTime($this->server->getGrantType('refresh_token')->getRefreshTokenTTL() + time());
|
||||||
$this->server->getTokenType()->set('refresh_token', $refreshToken->getId());
|
$this->server->getTokenType()->setParam('refresh_token', $refreshToken->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save everything
|
// Save everything
|
||||||
|
@ -139,8 +139,8 @@ class RefreshTokenGrant extends AbstractGrant
|
|||||||
$oldAccessToken->expire($this->server->getStorage('access_token'));
|
$oldAccessToken->expire($this->server->getStorage('access_token'));
|
||||||
$newAccessToken->save($this->server->getStorage('access_token'));
|
$newAccessToken->save($this->server->getStorage('access_token'));
|
||||||
|
|
||||||
$this->server->getTokenType()->set('access_token', $newAccessToken->getId());
|
$this->server->getTokenType()->setParam('access_token', $newAccessToken->getId());
|
||||||
$this->server->getTokenType()->set('expires_in', $this->getAccessTokenTTL());
|
$this->server->getTokenType()->setParam('expires_in', $this->getAccessTokenTTL());
|
||||||
|
|
||||||
// Expire the old refresh token
|
// Expire the old refresh token
|
||||||
$oldRefreshToken->expire($this->server->getStorage('refresh_token'));
|
$oldRefreshToken->expire($this->server->getStorage('refresh_token'));
|
||||||
@ -152,7 +152,7 @@ class RefreshTokenGrant extends AbstractGrant
|
|||||||
$newRefreshToken->setAccessToken($newAccessToken);
|
$newRefreshToken->setAccessToken($newAccessToken);
|
||||||
$newRefreshToken->save($this->server->getStorage('refresh_token'));
|
$newRefreshToken->save($this->server->getStorage('refresh_token'));
|
||||||
|
|
||||||
$this->server->getTokenType()->set('refresh_token', $newRefreshToken->getId());
|
$this->server->getTokenType()->setParam('refresh_token', $newRefreshToken->getId());
|
||||||
|
|
||||||
return $this->server->getTokenType()->generateResponse();
|
return $this->server->getTokenType()->generateResponse();
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ abstract class AbstractTokenType
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
public function set($key, $value)
|
public function setParam($key, $value)
|
||||||
{
|
{
|
||||||
$this->response[$key] = $value;
|
$this->response[$key] = $value;
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ abstract class AbstractTokenType
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function get($key)
|
public function getParam($key)
|
||||||
{
|
{
|
||||||
return isset($this->response[$key]) ? $this->response[$key] : null;
|
return isset($this->response[$key]) ? $this->response[$key] : null;
|
||||||
}
|
}
|
||||||
|
@ -21,13 +21,13 @@ class Bearer extends AbstractTokenType implements TokenTypeInterface
|
|||||||
public function generateResponse()
|
public function generateResponse()
|
||||||
{
|
{
|
||||||
$return = [
|
$return = [
|
||||||
'access_token' => $this->get('access_token'),
|
'access_token' => $this->getParam('access_token'),
|
||||||
'token_type' => 'Bearer',
|
'token_type' => 'Bearer',
|
||||||
'expires_in' => $this->get('expires_in')
|
'expires_in' => $this->getParam('expires_in')
|
||||||
];
|
];
|
||||||
|
|
||||||
if (!is_null($this->get('refresh_token'))) {
|
if (!is_null($this->getParam('refresh_token'))) {
|
||||||
$return['refresh_token'] = $this->get('refresh_token');
|
$return['refresh_token'] = $this->getParam('refresh_token');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $return;
|
return $return;
|
||||||
|
Loading…
Reference in New Issue
Block a user