Exemple #1
0
 /**
  * Issue an auth code.
  *
  * @param \DateInterval                                         $authCodeTTL
  * @param \League\OAuth2\Server\Entities\ClientEntityInterface  $client
  * @param string                                                $userIdentifier
  * @param string                                                $redirectUri
  * @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
  *
  * @return \League\OAuth2\Server\Entities\AuthCodeEntityInterface
  */
 protected function issueAuthCode(\DateInterval $authCodeTTL, ClientEntityInterface $client, $userIdentifier, $redirectUri, array $scopes = [])
 {
     $authCode = $this->authCodeRepository->getNewAuthCode();
     $authCode->setIdentifier($this->generateUniqueIdentifier());
     $authCode->setExpiryDateTime((new \DateTime())->add($authCodeTTL));
     $authCode->setClient($client);
     $authCode->setUserIdentifier($userIdentifier);
     $authCode->setRedirectUri($redirectUri);
     foreach ($scopes as $scope) {
         $authCode->addScope($scope);
     }
     $this->authCodeRepository->persistNewAuthCode($authCode);
     return $authCode;
 }
 /**
  * Issue an auth code.
  *
  * @param \DateInterval                                         $authCodeTTL
  * @param \League\OAuth2\Server\Entities\ClientEntityInterface  $client
  * @param string                                                $userIdentifier
  * @param string                                                $redirectUri
  * @param \League\OAuth2\Server\Entities\ScopeEntityInterface[] $scopes
  *
  * @return \League\OAuth2\Server\Entities\AuthCodeEntityInterface
  */
 protected function issueAuthCode(\DateInterval $authCodeTTL, ClientEntityInterface $client, $userIdentifier, $redirectUri, array $scopes = [])
 {
     $maxGenerationAttempts = self::MAX_RANDOM_TOKEN_GENERATION_ATTEMPTS;
     $authCode = $this->authCodeRepository->getNewAuthCode();
     $authCode->setExpiryDateTime((new \DateTime())->add($authCodeTTL));
     $authCode->setClient($client);
     $authCode->setUserIdentifier($userIdentifier);
     $authCode->setRedirectUri($redirectUri);
     foreach ($scopes as $scope) {
         $authCode->addScope($scope);
     }
     while ($maxGenerationAttempts-- > 0) {
         $authCode->setIdentifier($this->generateUniqueIdentifier());
         try {
             $this->authCodeRepository->persistNewAuthCode($authCode);
             return $authCode;
         } catch (UniqueTokenIdentifierConstraintViolationException $e) {
             if ($maxGenerationAttempts === 0) {
                 throw $e;
             }
         }
     }
 }