本文整理匯總了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.');
}
示例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;
}
示例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);
}
}
示例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;
}
}
}
示例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;
}