コード例 #1
0
ファイル: AccessTokenFacade.php プロジェクト: drahak/oauth2
 /**
  * Create access token
  * @param IClient $client
  * @param string|int $userId
  * @param array $scope
  * @return AccessToken
  */
 public function create(IClient $client, $userId, array $scope = array())
 {
     $accessExpires = new \DateTime();
     $accessExpires->modify('+' . $this->lifetime . ' seconds');
     $accessToken = new AccessToken($this->keyGenerator->generate(), $accessExpires, $client->getId(), $userId, $scope);
     $this->storage->store($accessToken);
     return $accessToken;
 }
コード例 #2
0
ファイル: OAuth2Presenter.php プロジェクト: lucien144/Restful
 /**
  * Issue an authorization code
  * @param string $responseType
  * @param string $redirectUrl
  * @param string|null $scope
  * @return void
  *
  * @throws UnauthorizedClientException
  * @throws UnsupportedResponseTypeException
  */
 public function issueAuthorizationCode($responseType, $redirectUrl, $scope = NULL)
 {
     try {
         if ($responseType !== 'code') {
             throw new UnsupportedResponseTypeException();
         }
         if (!$this->client->getId()) {
             throw new UnauthorizedClientException();
         }
         $scope = array_filter(explode(',', str_replace(' ', ',', $scope)));
         $code = $this->authorizationCode->create($this->client, $this->user->getId(), $scope);
         $data = array('code' => $code->getAuthorizationCode());
         $this->oauthResponse($data, $redirectUrl);
     } catch (OAuthException $e) {
         $this->oauthError($e);
     } catch (TokenException $e) {
         $this->oauthError(new InvalidGrantException());
     }
 }