/** * {@inheritDoc} */ public function authenticate(TokenInterface $token) { $ownerName = $token->getResourceOwnerName(); $oauthUtil = $this->container->get('glory_oauth.util.token2oauth'); $oauth = $oauthUtil->generate($token); $connect = $this->container->get('glory_oauth.connect'); if (!($user = $connect->getConnect($oauth))) { if ($this->container->getParameter('glory_oauth.auto_register')) { $user = $connect->connect($oauth); } else { $key = time(); $this->container->get('session')->set('glory_oauth.connect.oauth.' . $key, [$oauth->getOwner(), $oauth->getUsername()]); $url = $this->container->get('router')->generate('glory_oauth_register', ['key' => $key]); return new RedirectResponse($url); } } if (!$user instanceof UserInterface) { throw new BadCredentialsException(''); } 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->setOwnerName($ownerName); $token->setUser($user); $token->setAuthenticated(true); return $token; }
public function generate(OAuthToken $token) { $owner = $this->ownerMap->getOwner($token->getOwnerName()); $response = $owner->getUserInformation($token->getRawToken()); $oauth = $this->oauthManager->getOAuth($response->getUsername(), $owner->getName()); if (!$oauth) { $oauth = $this->oauthManager->createOAuth(); $oauth->setCreated(); $oauth->setOwner($owner->getName()); $oauth->setUsername($response->getUsername()); } $oauth->setNickname($response->getNickname()); $oauth->setFirstname($response->getFirstName()); $oauth->setLastname($response->getLastName()); $oauth->setRealname($response->getRealName()); $oauth->setEmail($response->getEmail()); $oauth->setAvatar($response->getProfilePicture()); $oauth->setAccesstoken($response->getAccessToken()); $oauth->setRefreshtoken($response->getRefreshToken()); $oauth->setTokensecret($response->getTokenSecret()); $oauth->setExpires($response->getExpiresIn()); $this->oauthManager->updateOAuth($oauth); return $oauth; }