mirror of
https://github.com/elyby/oauth2-server.git
synced 2025-01-03 10:41:51 +05:30
support grant specific access token ttl
This commit is contained in:
parent
9e2a6ed238
commit
1ff3d1adda
@ -80,6 +80,19 @@ abstract class AbstractGrant implements GrantTypeInterface
|
|||||||
return $this->responseType;
|
return $this->responseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the TTL for an access token
|
||||||
|
* @return int The TTL
|
||||||
|
*/
|
||||||
|
public function getAccessTokenTTL()
|
||||||
|
{
|
||||||
|
if ($this->accessTokenTTL) {
|
||||||
|
return $this->accessTokenTTL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->server->getAccessTokenTTL();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Override the default access token expire time
|
* Override the default access token expire time
|
||||||
* @param int $accessTokenTTL
|
* @param int $accessTokenTTL
|
||||||
|
@ -217,7 +217,7 @@ class AuthCodeGrant extends AbstractGrant
|
|||||||
// Generate the access token
|
// Generate the access token
|
||||||
$accessToken = new AccessTokenEntity($this->server);
|
$accessToken = new AccessTokenEntity($this->server);
|
||||||
$accessToken->setId(SecureKey::generate());
|
$accessToken->setId(SecureKey::generate());
|
||||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
$accessToken->setExpireTime($this->getAccessTokenTTL() + time());
|
||||||
|
|
||||||
foreach ($authCodeScopes as $authCodeScope) {
|
foreach ($authCodeScopes as $authCodeScope) {
|
||||||
$session->associateScope($authCodeScope);
|
$session->associateScope($authCodeScope);
|
||||||
@ -228,7 +228,7 @@ class AuthCodeGrant extends AbstractGrant
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getTokenType()->set('access_token', $accessToken->getId());
|
$this->server->getTokenType()->set('access_token', $accessToken->getId());
|
||||||
$this->server->getTokenType()->set('expires_in', $this->server->getAccessTokenTTL());
|
$this->server->getTokenType()->set('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')) {
|
||||||
|
@ -94,7 +94,7 @@ class ClientCredentialsGrant extends AbstractGrant
|
|||||||
// Generate an access token
|
// Generate an access token
|
||||||
$accessToken = new AccessTokenEntity($this->server);
|
$accessToken = new AccessTokenEntity($this->server);
|
||||||
$accessToken->setId(SecureKey::generate());
|
$accessToken->setId(SecureKey::generate());
|
||||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
$accessToken->setExpireTime($this->getAccessTokenTTL() + time());
|
||||||
|
|
||||||
// Associate scopes with the session and access token
|
// Associate scopes with the session and access token
|
||||||
foreach ($scopes as $scope) {
|
foreach ($scopes as $scope) {
|
||||||
@ -111,7 +111,7 @@ class ClientCredentialsGrant extends AbstractGrant
|
|||||||
$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()->set('access_token', $accessToken->getId());
|
||||||
$this->server->getTokenType()->set('expires_in', $this->server->getAccessTokenTTL());
|
$this->server->getTokenType()->set('expires_in', $this->getAccessTokenTTL());
|
||||||
|
|
||||||
return $this->server->getTokenType()->generateResponse();
|
return $this->server->getTokenType()->generateResponse();
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ class PasswordGrant extends AbstractGrant
|
|||||||
// Generate an access token
|
// Generate an access token
|
||||||
$accessToken = new AccessTokenEntity($this->server);
|
$accessToken = new AccessTokenEntity($this->server);
|
||||||
$accessToken->setId(SecureKey::generate());
|
$accessToken->setId(SecureKey::generate());
|
||||||
$accessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
$accessToken->setExpireTime($this->getAccessTokenTTL() + time());
|
||||||
|
|
||||||
// Associate scopes with the session and access token
|
// Associate scopes with the session and access token
|
||||||
foreach ($scopes as $scope) {
|
foreach ($scopes as $scope) {
|
||||||
@ -146,7 +146,7 @@ class PasswordGrant extends AbstractGrant
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getTokenType()->set('access_token', $accessToken->getId());
|
$this->server->getTokenType()->set('access_token', $accessToken->getId());
|
||||||
$this->server->getTokenType()->set('expires_in', $this->server->getAccessTokenTTL());
|
$this->server->getTokenType()->set('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')) {
|
||||||
|
@ -126,7 +126,7 @@ class RefreshTokenGrant extends AbstractGrant
|
|||||||
// Generate a new access token and assign it the correct sessions
|
// Generate a new access token and assign it the correct sessions
|
||||||
$newAccessToken = new AccessTokenEntity($this->server);
|
$newAccessToken = new AccessTokenEntity($this->server);
|
||||||
$newAccessToken->setId(SecureKey::generate());
|
$newAccessToken->setId(SecureKey::generate());
|
||||||
$newAccessToken->setExpireTime($this->server->getAccessTokenTTL() + time());
|
$newAccessToken->setExpireTime($this->getAccessTokenTTL() + time());
|
||||||
$newAccessToken->setSession($session);
|
$newAccessToken->setSession($session);
|
||||||
|
|
||||||
foreach ($newScopes as $newScope) {
|
foreach ($newScopes as $newScope) {
|
||||||
@ -138,7 +138,7 @@ class RefreshTokenGrant extends AbstractGrant
|
|||||||
$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()->set('access_token', $newAccessToken->getId());
|
||||||
$this->server->getTokenType()->set('expires_in', $this->server->getAccessTokenTTL());
|
$this->server->getTokenType()->set('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'));
|
||||||
|
@ -11,11 +11,6 @@ class StubAbstractGrant extends \League\OAuth2\Server\Grant\AbstractGrant
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAccessTokenTTL()
|
|
||||||
{
|
|
||||||
return $this->accessTokenTTL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAuthorizationServer()
|
public function getAuthorizationServer()
|
||||||
{
|
{
|
||||||
return $this->server;
|
return $this->server;
|
||||||
|
Loading…
Reference in New Issue
Block a user