Skip to content

Commit 662db48

Browse files
committed
Handled introspect exception
1 parent 0055142 commit 662db48

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Security/OAuth2Authenticator.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1111
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1212
use Symfony\Component\Security\Core\Exception\CustomUserMessageAuthenticationException;
13+
use Symfony\Component\Security\Core\Exception\TokenNotFoundException;
1314
use Symfony\Component\Security\Http\Authenticator\AbstractAuthenticator;
1415
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
1516
use Symfony\Component\Security\Http\Authenticator\Passport\Passport;
@@ -38,9 +39,11 @@ public function authenticate(Request $request): Passport
3839
throw new CustomUserMessageAuthenticationException('Authorization header cannot be empty.');
3940
}
4041

41-
$token = $this->introspectService->itrospect(
42-
substr($authorization, strlen('Bearer '))
43-
);
42+
try {
43+
$token = $this->introspectService->itrospect(substr($authorization, strlen('Bearer ')));
44+
} catch (\RuntimeException $e) {
45+
throw new TokenNotFoundException('Invalid token.', 0, $e);
46+
}
4447

4548
$event = $this->eventDispatcher?->dispatch(new TokenVerifiedEvent($token));
4649

0 commit comments

Comments
 (0)