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 586c0b9

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

File tree

2 files changed

+38
-0
lines changed
Filter options

2 files changed

+38
-0
lines changed
+32Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Security\Core\User;
13+
14+
use Symfony\Component\Security\Core\Exception\AuthenticationException;
15+
use Symfony\Component\Security\Core\Exception\UserNotFoundException;
16+
use Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge;
17+
18+
/**
19+
* @author Jeroen Spee <https://github.com/Jeroeny>
20+
*/
21+
interface TokenUserProviderInterface extends UserProviderInterface
22+
{
23+
/**
24+
* Loads the UserBadge for the given token.
25+
*
26+
* This method must throw UserNotFoundException if the user is not found.
27+
*
28+
* @throws UserNotFoundException
29+
* @throws AuthenticationException
30+
*/
31+
public function loadUserByToken(string $token): UserBadge;
32+
}

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Security/Http/Authenticator/AccessTokenAuthenticator.php
+6Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
1717
use Symfony\Component\Security\Core\Exception\AuthenticationException;
1818
use Symfony\Component\Security\Core\Exception\BadCredentialsException;
19+
use Symfony\Component\Security\Core\User\TokenUserProviderInterface;
1920
use Symfony\Component\Security\Core\User\UserProviderInterface;
2021
use Symfony\Component\Security\Http\AccessToken\AccessTokenExtractorInterface;
2122
use Symfony\Component\Security\Http\AccessToken\AccessTokenHandlerInterface;
@@ -58,6 +59,11 @@ public function authenticate(Request $request): Passport
5859
if (!$accessToken) {
5960
throw new BadCredentialsException('Invalid credentials.');
6061
}
62+
63+
if ($this->userProvider instanceof TokenUserProviderInterface) {
64+
return new SelfValidatingPassport($this->userProvider->loadUserByToken($accessToken));
65+
}
66+
6167
$userIdentifier = $this->accessTokenHandler->getUserIdentifierFrom($accessToken);
6268

6369
return new SelfValidatingPassport(

0 commit comments

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