/** * {@inheritDoc} */ public function authenticate(TokenInterface $token) { if (!$this->supports($token)) { return; } /* @var OAuthToken $token */ $resourceOwner = $this->resourceOwnerMap->getResourceOwnerByName($token->getResourceOwnerName()); $userResponse = $resourceOwner->getUserInformation($token->getRawToken()); try { $user = $this->userProvider->loadUserByOAuthUserResponse($userResponse); } catch (OAuthAwareExceptionInterface $e) { $e->setToken($token); $e->setResourceOwnerName($token->getResourceOwnerName()); throw $e; } if (!$user instanceof UserInterface) { throw new AuthenticationServiceException('loadUserByOAuthUserResponse() must return a UserInterface.'); } try { $this->userChecker->checkPreAuth($user); $this->userChecker->checkPostAuth($user); } catch (BadCredentialsException $e) { if ($this->hideUserNotFoundExceptions) { throw new BadCredentialsException('Bad credentials', 0, $e); } throw $e; } $token = new OAuthToken($token->getRawToken(), $user->getRoles()); $token->setResourceOwnerName($resourceOwner->getName()); $token->setUser($user); $token->setAuthenticated(true); return $token; }
/** * {@inheritDoc} */ public function authenticate(TokenInterface $token) { $resourceOwner = $this->resourceOwnerMap->getResourceOwnerByName($token->getResourceOwnerName()); $userResponse = $resourceOwner->getUserInformation($token->getCredentials()); try { $user = $this->userProvider->loadUserByOAuthUserResponse($userResponse); } catch (OAuthAwareExceptionInterface $e) { $e->setAccessToken($token->getCredentials()); $e->setResourceOwnerName($token->getResourceOwnerName()); throw $e; } $token = new OAuthToken($token->getCredentials(), $user->getRoles()); $token->setUser($user); $token->setAuthenticated(true); return $token; }
/** * @param string $name * * @return ResourceOwnerInterface * * @throws \RuntimeException */ protected function getResourceOwner($name) { $resourceOwner = $this->ownerMap->getResourceOwnerByName($name); if (!$resourceOwner instanceof ResourceOwnerInterface) { throw new \RuntimeException(sprintf("No resource owner with name '%s'.", $name)); } return $resourceOwner; }
/** * {@inheritDoc} */ public function authenticate(TokenInterface $token) { if (!$this->supports($token)) { return null; } /* @var OAuthToken $token */ $resourceOwner = $this->resourceOwnerMap->getResourceOwnerByName($token->getResourceOwnerName()); if ($token->getUser()) { $user = $this->userProvider->refreshUser($token->getUser()); } else { try { $userResponse = $resourceOwner->getUserInformation($token->getRawToken()); } catch (HttpTransportException $e) { $token = new AnonymousToken($token->getRawToken(), 'anon.'); $token->setAuthenticated(true); return $token; } catch (RequestException $e) { $token = new AnonymousToken($token->getRawToken(), 'anon.'); $token->setAuthenticated(true); return $token; } try { $user = $this->userProvider->loadUserByOAuthUserResponse($userResponse); } catch (OAuthAwareExceptionInterface $e) { $e->setToken($token); $e->setResourceOwnerName($token->getResourceOwnerName()); throw $e; } } if (!$user instanceof UserInterface) { throw new AuthenticationServiceException('loadUserByOAuthUserResponse() must return a UserInterface.'); } try { $this->userChecker->checkPreAuth($user); $this->userChecker->checkPostAuth($user); } catch (BadCredentialsException $e) { throw $e; } $token = new OAuthToken($token->getRawToken(), $user->getRoles()); $token->setResourceOwnerName($resourceOwner->getName()); $token->setUser($user); $token->setAuthenticated(true); return $token; }
/** * 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; }
/** * @param string $accessToken * * @return PathUserResponse */ public function getUserInfo($accessToken) { $resourceOwner = $this->resourceOwnerMap->getResourceOwnerByName(self::RESOURCE_OWNER_GOOGLE); return $resourceOwner->getUserInformation(['access_token' => $accessToken]); }