Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Security/Authenticator/KeycloakAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ public function authenticate(Request $request): Passport
{
$client = $this->getKeycloakClient();
$accessToken = $this->fetchAccessToken($client);
$keycloakUser = $client->fetchUserFromToken($accessToken);
$username = $keycloakUser->getPreferredUsername();
if (null === $accessToken) {
// The token header was empty, authentication fails with HTTP Status
// Code 401 "Unauthorized"
throw new CustomUserMessageAuthenticationException('No access token provided');
}

return new SelfValidatingPassport(
new UserBadge($accessToken->getToken(), function() use ($accessToken) {
new UserBadge($username, function() use ($accessToken) {
return $this->userProvider->loadUserByIdentifier($accessToken);
})
);
Expand Down