Skip to content

Commit 9a8ead1

Browse files
author
b-richard
committed
woups fix regression on JWT token generation
1 parent debd840 commit 9a8ead1

File tree

1 file changed

+7
-14
lines changed

1 file changed

+7
-14
lines changed

src/Security/JwtTokenTools.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class JwtTokenTools
2121
* @param $password
2222
* @param LoggerInterface|null $logger
2323
* @return string
24-
* @throws \Exception
24+
* @throws \Lexik\Bundle\JWTAuthenticationBundle\Exception\JWTEncodeFailureException
2525
*/
2626
public function encodeToken(
2727
InMemoryUserProvider $provider,
@@ -35,33 +35,26 @@ public function encodeToken(
3535
try {
3636
$user = $provider->loadUserByUsername($username);
3737

38-
if (!isset($user)) {
39-
throw new NotFoundHttpException();
40-
}
41-
4238
$isValid = $passwordEncoder
4339
->isPasswordValid($user, $password);
4440

4541
if (!$isValid) {
4642
throw new BadCredentialsException();
4743
}
4844

49-
return $encoder->encode([
45+
$token = $encoder->encode([
5046
'username' => $username,
5147
'exp' => time() * $tokenJwtTtl
5248
]);
53-
} catch (UsernameNotFoundException $e) {
54-
if ($logger) {
55-
$logger->alert(sprintf('Exception: UsernameNotFoundException: %s', $e->getMessage()));
56-
}
5749

58-
throw $e;
59-
} catch (BadCredentialsException $e) {
50+
return $token;
51+
} catch (UsernameNotFoundException $e) {
52+
$msg = sprintf('Exception: UsernameNotFoundException: %s', $e->getMessage());
6053
if ($logger) {
61-
$logger->alert(sprintf('Exception: BadCredentialsException: %s', $e->getMessage()));
54+
$logger->alert($msg);
6255
}
6356

64-
throw $e;
57+
throw new NotFoundHttpException($msg);
6558
} catch (\Exception $e) {
6659
if ($logger) {
6760
$logger->alert(sprintf('Exception: \Exception: %s', $e->getMessage()));

0 commit comments

Comments
 (0)