本文整理汇总了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;
}