Пример #1
0
 /**
  * Issue an access token.
  *
  * @param \DateInterval                                         $accessTokenTTL
  * @param \League\OAuth2\Server\Entities\ClientEntityInterface  $client
  * @param string                                                $userIdentifier
  * @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
  *
  * @return \League\OAuth2\Server\Entities\AccessTokenEntityInterface
  */
 protected function issueAccessToken(\DateInterval $accessTokenTTL, ClientEntityInterface $client, $userIdentifier, array $scopes = [])
 {
     $accessToken = $this->accessTokenRepository->getNewToken($client, $scopes, $userIdentifier);
     $accessToken->setClient($client);
     $accessToken->setUserIdentifier($userIdentifier);
     $accessToken->setIdentifier($this->generateUniqueIdentifier());
     $accessToken->setExpiryDateTime((new \DateTime())->add($accessTokenTTL));
     foreach ($scopes as $scope) {
         $accessToken->addScope($scope);
     }
     $this->accessTokenRepository->persistNewAccessToken($accessToken);
     return $accessToken;
 }
 /**
  * Issue an access token.
  *
  * @param \DateInterval                                         $accessTokenTTL
  * @param \League\OAuth2\Server\Entities\ClientEntityInterface  $client
  * @param string                                                $userIdentifier
  * @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
  *
  * @return \League\OAuth2\Server\Entities\AccessTokenEntityInterface
  */
 protected function issueAccessToken(\DateInterval $accessTokenTTL, ClientEntityInterface $client, $userIdentifier, array $scopes = [])
 {
     $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS;
     $accessToken = $this->accessTokenRepository->getNewToken($client, $scopes, $userIdentifier);
     $accessToken->setClient($client);
     $accessToken->setUserIdentifier($userIdentifier);
     $accessToken->setExpiryDateTime((new \DateTime())->add($accessTokenTTL));
     foreach ($scopes as $scope) {
         $accessToken->addScope($scope);
     }
     while ($maxGenerationAttempts-- > 0) {
         $accessToken->setIdentifier($this->generateUniqueIdentifier());
         try {
             $this->accessTokenRepository->persistNewAccessToken($accessToken);
             return $accessToken;
         } catch (UniqueTokenIdentifierConstraintViolationException $e) {
             if ($maxGenerationAttempts === 0) {
                 throw $e;
             }
         }
     }
 }