예제 #1
0
 public function authenticate(TokenInterface $token)
 {
     $user = $this->userProvider->loadUserByUsername($token->getUsername());
     if ($user) {
         $authencatedToken = new FacebookUserToken(['ROLE_FACEBOOK_USER']);
         $authencatedToken->setUser($user);
         return $authencatedToken;
     }
     throw new AuthenticationException('Facebook authentication failed.');
 }
예제 #2
0
 public function handle(GetResponseEvent $event)
 {
     $helper = $this->facebook->getRedirectLoginHelper();
     try {
         $accessToken = $helper->getAccessToken();
         if (!$accessToken) {
             return;
         }
         $response = $this->facebook->get('/me', $accessToken);
         $user = $response->getGraphNode(FacebookUser::class);
         $token = new FacebookUserToken();
         $token->setUser($user);
         $authToken = $this->authenticationManager->authenticate($token);
         $this->tokenStorage->setToken($authToken);
         return;
     } catch (FacebookResponseException $e) {
         $this->logger->info(sprintf('FacebookResponseException: %s', $e->getMessage()));
     } catch (FacebookSDKException $e) {
         $this->logger->warning(sprintf('FacebookSDKException: %s', $e->getMessage()));
     } catch (AuthenticationException $e) {
         $this->logger->info(sprintf('AuthenticationException: %s', $e->getMessage()));
     }
     $event->setResponse(new RedirectResponse('/login'));
 }