/** * {@inheritDoc} */ public function authenticate(TokenInterface $token) { $user = $this->userProvider->loadUserByUsername($token->getUsername()); if ($user) { $authenticatedToken = new OAuthToken($user->getRoles(), $token->getResponse()); $authenticatedToken->setAuthenticated(true); $authenticatedToken->setUser($user); return $authenticatedToken; } throw new AuthenticationException('OAuth Authentication Failed.'); }
/** * {@inheritDoc} */ protected function attemptAuthentication(Request $request) { // redirect to auth provider if ($this->httpUtils->checkRequestPath($request, $this->options['login_path'])) { return $this->createProviderRedirectResponse($request); } $code = $request->get('code'); $token = $this->oauthProvider->createTokenResponse($this->options['client_id'], $this->options['client_secret'], $code, $this->assembleRedirectUrl($this->options['check_path'], $request)); if (is_null($token)) { throw new AuthenticationException('Authentication failed'); } if (null === $this->options['uid']) { $username = $token->getUsername(); } else { $username = $token->getUsername($this->options['uid']); } $authToken = new OAuthToken(array(), $token); $authToken->setUser($username); return $this->authenticationManager->authenticate($authToken); }