Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6e938f4

Browse filesBrowse files
committed
support loading UserBadge directly from accessToken
1 parent 521d210 commit 6e938f4
Copy full SHA for 6e938f4

File tree

2 files changed

+5
-3
lines changed
Filter options

2 files changed

+5
-3
lines changed

‎src/Symfony/Component/Security/Http/AccessToken/AccessTokenHandlerInterface.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/AccessToken/AccessTokenHandlerInterface.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Security\Http\AccessToken;
1313

1414
use Symfony\Component\Security\Core\Exception\AuthenticationException;
15+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
1516

1617
/**
1718
* The token handler retrieves the user identifier from the token.
@@ -24,5 +25,5 @@ interface AccessTokenHandlerInterface
2425
/**
2526
* @throws AuthenticationException
2627
*/
27-
public function getUserIdentifierFrom(#[\SensitiveParameter] string $accessToken): string;
28+
public function getUserIdentifierFrom(#[\SensitiveParameter] string $accessToken): UserBadge|string;
2829
}

‎src/Symfony/Component/Security/Http/Authenticator/AccessTokenAuthenticator.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/AccessTokenAuthenticator.php
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ public function authenticate(Request $request): Passport
5858
if (!$accessToken) {
5959
throw new BadCredentialsException('Invalid credentials.');
6060
}
61-
$userIdentifier = $this->accessTokenHandler->getUserIdentifierFrom($accessToken);
61+
62+
$user = $this->accessTokenHandler->getUserIdentifierFrom($accessToken);
6263

6364
return new SelfValidatingPassport(
64-
new UserBadge($userIdentifier, $this->userProvider->loadUserByIdentifier(...))
65+
$user instanceof UserBadge ? $user : new UserBadge($user, $this->userProvider->loadUserByIdentifier(...))
6566
);
6667
}
6768

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.