function it_does_not_get_user_because_user_is_inactive(JWTEncoderInterface $jwtEncoder, UserProviderInterface $userProvider, User $user) { $jwtEncoder->decode('bearer-token')->shouldBeCalled()->willReturn(['email' => '*****@*****.**']); $userProvider->loadUserByUsername('*****@*****.**')->shouldBeCalled()->willReturn($user); $user->confirmationToken = 'confirmation-token'; $user->invitationToken = null; $this->shouldThrow(new CustomUserMessageAuthenticationException('The user does not exist'))->duringGetUser('bearer-token', $userProvider); }
public function getUser($credentials, UserProviderInterface $userProvider) { $data = $this->jwtEncoder->decode($credentials); if ($data === false) { throw new CustomUserMessageAuthenticationException('Invalid Token'); } $username = $data['username']; return $this->em->getRepository('AppBundle:User')->findOneBy(['username' => $username]); }
/** * {@inheritdoc} */ public function decode(TokenInterface $token) { if (!($payload = $this->jwtEncoder->decode($token->getCredentials()))) { return false; } $event = new JWTDecodedEvent($payload, $this->request); $this->dispatcher->dispatch(Events::JWT_DECODED, $event); if (!$event->isValid()) { return false; } return $payload; }
/** * {@inheritdoc} */ public function getUser($credentials, UserProviderInterface $userProvider) { $data = $this->jwtEncoder->decode($credentials); if (false === $data) { throw new CustomUserMessageAuthenticationException('The given token is invalid'); } $user = $userProvider->loadUserByUsername($data['email']); if (null !== $user->confirmationToken || null !== $user->invitationToken) { throw new CustomUserMessageAuthenticationException('The user does not exist'); } return $user; }