Beispiel #1
0
 /**
  * Attempts to authenticate a TokenInterface object.
  *
  * @param OAuthToken $token The TokenInterface instance to authenticate
  *
  * @return TokenInterface An authenticated TokenInterface instance, never null
  *
  * @throws AuthenticationException if the authentication fails
  */
 public function authenticate(TokenInterface $token)
 {
     $resourceOwner = $this->resourceOwnerMap->getResourceOwnerByName($token->getResourceOwnerName());
     try {
         $userResponse = $resourceOwner->getUserInformation($token->getRawToken());
         $user = $this->userProvider->loadUserByOAuthUserResponse($userResponse);
     } catch (OAuthAwareExceptionInterface $e) {
         $e->setToken($token);
         $e->setResourceOwnerName($token->getResourceOwnerName());
         throw $e;
     }
     $organization = $this->guessOrganization($user, $token);
     $token = new OAuthToken($token->getRawToken(), $user->getRoles());
     $token->setResourceOwnerName($resourceOwner->getName());
     $token->setOrganizationContext($organization);
     $token->setUser($user);
     $token->setAuthenticated(true);
     $this->userChecker->checkPostAuth($user);
     return $token;
 }