Exemplo n.º 1
0
 public function createAccessToken(AccessTokenInterface $accessToken, $client_id, $user_id, $scope)
 {
     $token = parent::createAccessToken($accessToken, $client_id, $user_id, $scope);
     if (array_key_exists('session_state', $token) === false) {
         $sessionState = $this->sessionStateStorage->getSessionState($client_id, $this->authCode['session_id']);
         $token['session_state'] = $sessionState;
     }
     return $token;
 }
Exemplo n.º 2
0
 /**
  * Take the provided authorization code values and store them somewhere.
  *
  * This function should be the storage counterpart to getAuthCode().
  *
  * If storage fails for some reason, we're not currently checking for
  * any sort of success/failure, so you should bail out of the script
  * and provide a descriptive fail message.
  *
  * Required for OAuth2::GRANT_TYPE_AUTH_CODE.
  *
  * @param $code
  * Authorization code to be stored.
  * @param $client_id
  * Client identifier to be stored.
  * @param $user_id
  * User identifier to be stored.
  * @param string $redirect_uri
  *                             Redirect URI(s) to be stored in a space-separated string.
  * @param int    $expires
  *                             Expiration to be stored as a Unix timestamp.
  * @param string $scope
  *                             (optional) Scopes to be stored in space-separated string.
  *
  * @ingroup oauth2_section_4
  */
 public function setAuthorizationCode($code, $client_id, $user_id, $redirect_uri, $expires, $scope = null, $id_token = null)
 {
     $id = explode('_', $client_id);
     $client = $this->em->getRepository('PROCERGSOAuthBundle:Client')->find($id[0]);
     if ($user_id === null) {
         $user = null;
     } else {
         $user = $this->em->getRepository('PROCERGSLoginCidadaoCoreBundle:Person')->find($user_id);
     }
     if (!$client) {
         throw new \Exception('Unknown client identifier');
     }
     $authorizationCode = new \PROCERGS\OAuthBundle\Entity\AuthCode();
     $authorizationCode->setToken($code);
     $authorizationCode->setClient($client);
     $authorizationCode->setUser($user);
     $authorizationCode->setRedirectUri($redirect_uri);
     $authorizationCode->setExpiresAt($expires);
     $authorizationCode->setScope($scope);
     $authorizationCode->setIdToken($id_token);
     $authorizationCode->setSessionId($this->sessionStateStorage->getSessionId());
     $this->em->persist($authorizationCode);
     $this->em->flush();
 }