Esempio n. 1
0
 public function authenticate(TokenInterface $token)
 {
     if (!$this->supports($token)) {
         return;
     }
     /* @var $token \Trismegiste\OAuthBundle\Security\Token */
     try {
         $found = $this->userProvider->findByOauthId($token->getProviderKey(), $token->getUserUniqueIdentifier());
     } catch (Exception $notFound) {
         throw new BadCredentialsException('Bad credentials', 0, $notFound);
     }
     if (!$found instanceof UserInterface) {
         throw new AuthenticationServiceException('findByOauthId() must return a UserInterface.');
     }
     $authenticatedToken = new Token($this->firewallName, $token->getProviderKey(), $token->getUserUniqueIdentifier(), $found->getRoles());
     $authenticatedToken->setAttributes($token->getAttributes());
     $authenticatedToken->setUser($found);
     return $authenticatedToken;
 }