예제 #1
0
 public function tokenAction()
 {
     $shib = $this->container->get('ilios_authentication.shibboleth.authentication');
     if ($user = $shib->getUser()) {
         $jwtKey = $this->container->getParameter('kernel.secret');
         $token = new JwtToken($jwtKey);
         $token->setUser($user);
         return new JsonResponse(array('jwt' => $token->getJwt()), JsonResponse::HTTP_OK);
     }
     return new JsonResponse(array('jwt' => null), JsonResponse::HTTP_OK);
 }
예제 #2
0
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     try {
         $authentication = $userProvider->loadUserByUsername($token->getUsername());
         $user = $authentication->getUser();
     } catch (UsernameNotFoundException $e) {
         throw new AuthenticationException('Invalid username or password');
     }
     $passwordValid = $this->encoder->isPasswordValid($user, $token->getCredentials());
     if ($passwordValid) {
         $token = new JwtToken($this->jwtKey);
         $token->setUser($user);
         return $token;
     }
     throw new AuthenticationException('Invalid username or password');
 }
예제 #3
0
파일: Listener.php 프로젝트: profcab/ilios
 public function handle(GetResponseEvent $event)
 {
     $request = $event->getRequest();
     try {
         $token = new JwtToken($this->jwtKey);
         $token->setRequest($request);
         if ($token->isValidJwtRequest()) {
             $authToken = $this->authenticationManager->authenticate($token);
             $this->tokenStorage->setToken($authToken);
         }
     } catch (\UnexpectedValueException $e) {
         throw new BadCredentialsException('Invalid JSON Web Token: ' . $e->getMessage());
         return null;
     } catch (AuthenticationException $failed) {
         //We have a token with a bad user id, move on and let
         //another login method handle this
         return;
     }
     return;
 }