From d3158a830b53413ffeb2b82a6bfda5e90113b3b1 Mon Sep 17 00:00:00 2001 From: jlehner Date: Thu, 26 Sep 2013 14:40:56 -0400 Subject: [PATCH] Update Implicit Grant Type with the following: - Added accessTokenTTL variable and setter method - Updated response in the completeFlow method to include all required parameters per OAuth2 spec - completeFlow function accounts for local grant TTL override --- src/League/OAuth2/Server/Grant/Implicit.php | 24 +++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/League/OAuth2/Server/Grant/Implicit.php b/src/League/OAuth2/Server/Grant/Implicit.php index f8d1f7e7..05809e28 100644 --- a/src/League/OAuth2/Server/Grant/Implicit.php +++ b/src/League/OAuth2/Server/Grant/Implicit.php @@ -42,6 +42,12 @@ class Implicit implements GrantTypeInterface { */ protected $authServer = null; + /** + * Access token expires in override + * @var int + */ + protected $accessTokenTTL = null; + /** * Constructor * @param Authorization $authServer Authorization server instance @@ -70,6 +76,16 @@ class Implicit implements GrantTypeInterface { return $this->responseType; } + /** + * Override the default access token expire time + * @param int $accessTokenTTL + * @return void + */ + public function setAccessTokenTTL($accessTokenTTL) + { + $this->accessTokenTTL = $accessTokenTTL; + } + /** * Complete the client credentials grant * @param null|array $inputParams @@ -84,7 +100,8 @@ class Implicit implements GrantTypeInterface { $accessToken = SecureKey::make(); // Compute expiry time - $accessTokenExpires = time() + $this->authServer->getAccessTokenTTL(); + $accessTokenExpiresIn = ($this->accessTokenTTL !== null) ? $this->accessTokenTTL : $this->authServer->getAccessTokenTTL(); + $accessTokenExpires = time() + $accessTokenExpiresIn; // Create a new session $sessionId = $this->authServer->getStorage('session')->createSession($authParams['client_id'], 'user', $authParams['user_id']); @@ -98,7 +115,10 @@ class Implicit implements GrantTypeInterface { } $response = array( - 'access_token' => $accessToken + 'access_token' => $accessToken, + 'token_type' => 'Bearer', + 'expires' => $accessTokenExpires, + 'expires_in' => $accessTokenExpiresIn, ); return $response;