File tree 2 files changed +38
-0
lines changed
Filter options
src/Symfony/Component/Security
2 files changed +38
-0
lines changed
Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 16
16
use Symfony \Component \Security \Core \Authentication \Token \TokenInterface ;
17
17
use Symfony \Component \Security \Core \Exception \AuthenticationException ;
18
18
use Symfony \Component \Security \Core \Exception \BadCredentialsException ;
19
+ use Symfony \Component \Security \Core \User \TokenUserProviderInterface ;
19
20
use Symfony \Component \Security \Core \User \UserProviderInterface ;
20
21
use Symfony \Component \Security \Http \AccessToken \AccessTokenExtractorInterface ;
21
22
use Symfony \Component \Security \Http \AccessToken \AccessTokenHandlerInterface ;
@@ -58,6 +59,11 @@ public function authenticate(Request $request): Passport
58
59
if (!$ accessToken ) {
59
60
throw new BadCredentialsException ('Invalid credentials. ' );
60
61
}
62
+
63
+ if ($ this ->userProvider instanceof TokenUserProviderInterface) {
64
+ return new SelfValidatingPassport ($ this ->userProvider ->loadUserByToken ($ accessToken ));
65
+ }
66
+
61
67
$ userIdentifier = $ this ->accessTokenHandler ->getUserIdentifierFrom ($ accessToken );
62
68
63
69
return new SelfValidatingPassport (
You can’t perform that action at this time.
0 commit comments