$ttlNames = array_keys($tokenTTLs);
     $tokenTTL = $tokenTTLs[$ttlNames[0]];
 }
 if (isset($client['expire'])) {
     $clientGracePeriod = $config->getValue('client_grace_period', 30 * 24 * 60 * 60);
     $now = time();
     if ($client['expire'] < $now + $clientGracePeriod / 2) {
         $client['expire'] = $now + $clientGracePeriod;
         $clientStore->updateClient($client);
     }
 }
 $idAttribute = $config->getValue('user_id_attribute', 'eduPersonScopedAffiliation');
 $attributes = $as->getAttributes();
 if ($state['response_type'] === 'code') {
     $authorizationCodeFactory = new sspmod_oauth2server_OAuth2_TokenFactory($authorizationCodeTTL, $accessTokenTTL, $tokenTTL);
     $token = $authorizationCodeFactory->createAuthorizationCode($state['clientId'], $state['redirectUri'], array(), $attributes[$idAttribute][0]);
 } else {
     $authorizationCodeFactory = new sspmod_oauth2server_OAuth2_TokenFactory($authorizationCodeTTL, $tokenTTL, $tokenTTL);
     $token = $authorizationCodeFactory->createBearerAccessToken($state['clientId'], array(), $attributes[$idAttribute][0]);
 }
 if (isset($_REQUEST['grantedScopes'])) {
     $scopesTemp = $_REQUEST['grantedScopes'];
 } else {
     $scopesTemp = array();
 }
 \sspmod_oauth2server_Utility_Uri::augmentRequestedScopesWithRequiredScopes($client, $scopesTemp);
 $token['scopes'] = \sspmod_oauth2server_Utility_Uri::findValidScopes($client, $scopesTemp);
 $tokenStore = new sspmod_oauth2server_OAuth2_TokenStore($config);
 if ($state['response_type'] === 'code') {
     $tokenStore->addAuthorizationCode($token);
 } else {