@@ -826,14 +826,16 @@ public function grantAccessToken(Request $request = null)
826
826
827
827
// if no scope provided to check against $input['scope'] then application defaults are set
828
828
// if no data is provided than null is set
829
- $ stored += array ('scope ' => $ this ->getVariable (self ::CONFIG_SUPPORTED_SCOPES , null ), 'data ' => null );
829
+ $ stored += array ('scope ' => $ this ->getVariable (self ::CONFIG_SUPPORTED_SCOPES , null ), 'data ' => null ,
830
+ 'access_token_lifetime ' => $ this ->getVariable (self ::CONFIG_ACCESS_LIFETIME ),
831
+ 'issue_refresh_token ' => true , 'refresh_token_lifetime ' => $ this ->getVariable (self ::CONFIG_REFRESH_LIFETIME ));
830
832
831
833
// Check scope, if provided
832
834
if ($ input ["scope " ] && (!isset ($ stored ["scope " ]) || !$ this ->checkScope ($ input ["scope " ], $ stored ["scope " ]))) {
833
835
throw new OAuth2ServerException (self ::HTTP_BAD_REQUEST , self ::ERROR_INVALID_SCOPE , 'An unsupported scope was requested. ' );
834
836
}
835
837
836
- $ token = $ this ->createAccessToken ($ client , $ stored ['data ' ], $ stored ['scope ' ]);
838
+ $ token = $ this ->createAccessToken ($ client , $ stored ['data ' ], $ stored ['scope ' ], $ stored [ ' access_token_lifetime ' ], $ stored [ ' issue_refresh_token ' ], $ stored [ ' refresh_token_lifetime ' ] );
837
839
838
840
return new Response (json_encode ($ token ), 200 , $ this ->getJsonHeaders ());
839
841
}
@@ -1287,19 +1289,22 @@ private function buildUri($uri, $params)
1287
1289
*
1288
1290
* @param IOAuth2Client $client
1289
1291
* @param mixed $data
1290
- * @param null $scope
1292
+ * @param string|null $scope
1293
+ * @param int|null $access_token_lifetime How long the access token should live in seconds
1294
+ * @param bool $issue_refresh_token Issue a refresh tokeniIf true and the storage mechanism supports it
1295
+ * @param int|null $refresh_token_lifetime How long the refresh token should life in seconds
1291
1296
*
1292
1297
* @return array
1293
1298
*
1294
1299
* @see http://tools.ietf.org/html/draft-ietf-oauth-v2-20#section-5
1295
1300
*
1296
1301
* @ingroup oauth2_section_5
1297
1302
*/
1298
- public function createAccessToken (IOAuth2Client $ client , $ data , $ scope = null )
1303
+ public function createAccessToken (IOAuth2Client $ client , $ data , $ scope = null , $ access_token_lifetime = null , $ issue_refresh_token = true , $ refresh_token_lifetime = null )
1299
1304
{
1300
1305
$ token = array (
1301
1306
"access_token " => $ this ->genAccessToken (),
1302
- "expires_in " => $ this ->getVariable (self ::CONFIG_ACCESS_LIFETIME ),
1307
+ "expires_in " => ( $ access_token_lifetime ?: $ this ->getVariable (self ::CONFIG_ACCESS_LIFETIME ) ),
1303
1308
"token_type " => $ this ->getVariable (self ::CONFIG_TOKEN_TYPE ),
1304
1309
"scope " => $ scope ,
1305
1310
);
@@ -1308,18 +1313,18 @@ public function createAccessToken(IOAuth2Client $client, $data, $scope = null)
1308
1313
$ token ["access_token " ],
1309
1314
$ client ,
1310
1315
$ data ,
1311
- time () + $ this ->getVariable (self ::CONFIG_ACCESS_LIFETIME ),
1316
+ time () + ( $ access_token_lifetime ?: $ this ->getVariable (self ::CONFIG_ACCESS_LIFETIME ) ),
1312
1317
$ scope
1313
1318
);
1314
1319
1315
1320
// Issue a refresh token also, if we support them
1316
- if ($ this ->storage instanceof IOAuth2RefreshTokens) {
1321
+ if ($ this ->storage instanceof IOAuth2RefreshTokens && $ issue_refresh_token === true ) {
1317
1322
$ token ["refresh_token " ] = $ this ->genAccessToken ();
1318
1323
$ this ->storage ->createRefreshToken (
1319
1324
$ token ["refresh_token " ],
1320
1325
$ client ,
1321
1326
$ data ,
1322
- time () + $ this ->getVariable (self ::CONFIG_REFRESH_LIFETIME ),
1327
+ time () + ( $ refresh_token_lifetime ?: $ this ->getVariable (self ::CONFIG_REFRESH_LIFETIME ) ),
1323
1328
$ scope
1324
1329
);
1325
1330
0 commit comments