当前位置: 首页>>代码示例>>PHP>>正文


PHP TokenInterface::getAccessToken方法代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getAccessToken方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenInterface::getAccessToken方法的具体用法?PHP TokenInterface::getAccessToken怎么用?PHP TokenInterface::getAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Security\Core\Authentication\Token\TokenInterface的用法示例。


在下文中一共展示了TokenInterface::getAccessToken方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: authenticate

 public function authenticate(TokenInterface $token)
 {
     try {
         $user = $this->userProvider->loadUserByAccessToken($token->getAccessToken());
         $authenticatedToken = new OAuth2Token($user->getRoles());
         $authenticatedToken->setAccessToken($token->getAccessToken());
         $authenticatedToken->setRefreshToken($token->getRefreshToken());
         $authenticatedToken->setUser($user);
         return $authenticatedToken;
     } catch (\Exception $e) {
         throw new AuthenticationException('The OAuth2 Access Token is invalid.');
     }
     throw new AuthenticationException('OAuth2 authentication failed.');
 }
开发者ID:jdelaune,项目名称:oauth2-client-bundle,代码行数:14,代码来源:OAuth2Provider.php

示例2: authenticate

 /**
  * {@inheritDoc}
  */
 public function authenticate(TokenInterface $token)
 {
     $resourceOwner = $this->resourceOwnerMap->getResourceOwnerByName($token->getResourceOwnerName());
     $userResponse = $resourceOwner->getUserInformation($token->getAccessToken());
     try {
         $user = $this->userProvider->loadUserByOAuthUserResponse($userResponse);
     } catch (OAuthAwareExceptionInterface $e) {
         $e->setAccessToken($token->getAccessToken());
         $e->setResourceOwnerName($token->getResourceOwnerName());
         throw $e;
     }
     $token = new OAuthToken($token->getAccessToken(), $user->getRoles());
     $token->setResourceOwnerName($resourceOwner->getName());
     $token->setUser($user);
     $token->setAuthenticated(true);
     return $token;
 }
开发者ID:nickrouty,项目名称:HWIOAuthBundle,代码行数:20,代码来源:OAuthProvider.php

示例3: authenticate

 public function authenticate(TokenInterface $token)
 {
     try {
         $localUser = $this->userProvider->loadUserByUsername($token->getUser());
         $authorizedToken = new ConnectToken($localUser, $token->getAccessToken(), $token->getApiUser(), $this->providerKey, $token->getScope(), $localUser->getRoles());
         $authorizedToken->setAttributes($token->getAttributes());
         return $authorizedToken;
     } catch (\Exception $repositoryProblem) {
         throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem);
     }
 }
开发者ID:nfabre,项目名称:connect,代码行数:11,代码来源:ConnectAuthenticationProvider.php

示例4: authenticate

 /**
  * Attempts to authenticate a TokenInterface object.
  *
  * @param TokenInterface $token The TokenInterface instance to authenticate
  *
  * @throws TokenBlockedHttpException
  * @throws TokenExpiredHttpException
  * @throws UserNotFoundHttpException
  * @return TokenInterface An authenticated TokenInterface instance, never null
  */
 public function authenticate(TokenInterface $token)
 {
     $accessToken = $token->getAccessToken();
     $accessTokenEntity = $this->accessTokenRepository->findOneByCode($accessToken);
     if (is_null($accessTokenEntity) || $accessTokenEntity->isBlocked()) {
         throw new TokenBlockedHttpException();
     }
     if ($accessTokenEntity->isExpired()) {
         throw new TokenExpiredHttpException();
     }
     $authenticatedToken = OAuth2Token::createFromAccessTokenEntity($accessTokenEntity);
     return $authenticatedToken;
 }
开发者ID:open-orchestra,项目名称:open-orchestra-base-api-bundle,代码行数:23,代码来源:OAuth2AuthenticationProvider.php

示例5: authenticate

 public function authenticate(TokenInterface $token)
 {
     try {
         $localUser = $this->userProvider->loadUserByUsername($token->getUser());
         $authorizedToken = new ConnectToken($localUser, $token->getAccessToken(), $token->getApiUser(), $this->providerKey, $token->getScope(), $localUser->getRoles());
         $authorizedToken->setAttributes($token->getAttributes());
         return $authorizedToken;
     } catch (\Exception $repositoryProblem) {
         if (!method_exists('Symfony\\Component\\Security\\Core\\Exception\\AuthenticationServiceException', 'setToken')) {
             throw new AuthenticationServiceException($repositoryProblem->getMessage(), $token, 0, $repositoryProblem);
         } else {
             $e = new AuthenticationServiceException($repositoryProblem->getMessage(), 0, $repositoryProblem);
             $e->setToken($token);
             throw $e;
         }
     }
 }
开发者ID:KinaMarie,项目名称:connect,代码行数:17,代码来源:ConnectAuthenticationProvider.php

示例6: authenticateAccessToken

 /**
  * Authenticate with access token
  *
  * @param  TokenInterface $token
  * @return OAuth2AccessToken
  */
 protected function authenticateAccessToken(TokenInterface $token)
 {
     $accessToken = $this->accessTokenProvider->get($token->getAccessToken());
     $this->checkAccessToken($accessToken);
     $client = $this->clientProvider->get($accessToken->getClient());
     $this->checkClient($client);
     $this->checkSignature($token, $client);
     // check scope
     $user = $this->userProvider->loadUserByUsername($accessToken->getUsername());
     try {
         $this->userChecker->checkPreAuth($user);
     } catch (AccountStatusException $e) {
         throw new OAuthAccessTokenNotFoundException($e->getMessage(), 401, $e, $this->realmName);
     }
     $retval = new OAuth2AccessToken($user->getRoles());
     $retval->setAuthenticated(true);
     $retval->setAccessToken($accessToken->getId());
     $retval->setUser($user);
     $retval->setClient($client);
     $retval->setSignature($token->getSignature());
     return $retval;
 }
开发者ID:euskadi31,项目名称:OAuth2ServerServiceProvider,代码行数:28,代码来源:OAuth2AuthenticationProvider.php


注:本文中的Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getAccessToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。