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.'); }
/** * {@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; }
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); } }
/** * 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; }
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; } } }
/** * 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; }