File tree Expand file tree Collapse file tree 2 files changed +16
-9
lines changed
Authentication/Authenticators Expand file tree Collapse file tree 2 files changed +16
-9
lines changed Original file line number Diff line number Diff line change @@ -108,10 +108,6 @@ public function check(array $credentials): Result
108108 ]);
109109 }
110110
111- if (strpos ($ credentials ['token ' ], 'Bearer ' ) === 0 ) {
112- $ credentials ['token ' ] = trim (substr ($ credentials ['token ' ], 6 ));
113- }
114-
115111 // Check JWT
116112 try {
117113 $ this ->payload = $ this ->decodeJWT ($ credentials ['token ' ]);
Original file line number Diff line number Diff line change @@ -37,11 +37,9 @@ public function before(RequestInterface $request, $arguments = null)
3737 /** @var JWT $authenticator */
3838 $ authenticator = auth ('jwt ' )->getAuthenticator ();
3939
40- $ result = $ authenticator ->attempt ([
41- 'token ' => $ request ->getHeaderLine (
42- setting ('Auth.authenticatorHeader ' )['jwt ' ] ?? 'Authorization '
43- ),
44- ]);
40+ $ token = $ this ->getTokenFromHeader ($ request );
41+
42+ $ result = $ authenticator ->attempt (['token ' => $ token ]);
4543
4644 if (! $ result ->isOK ()) {
4745 return Services::response ()
@@ -56,6 +54,19 @@ public function before(RequestInterface $request, $arguments = null)
5654 }
5755 }
5856
57+ private function getTokenFromHeader (RequestInterface $ request ): string
58+ {
59+ $ tokenHeader = $ request ->getHeaderLine (
60+ setting ('Auth.authenticatorHeader ' )['jwt ' ] ?? 'Authorization '
61+ );
62+
63+ if (strpos ($ tokenHeader , 'Bearer ' ) === 0 ) {
64+ return trim (substr ($ tokenHeader , 6 ));
65+ }
66+
67+ return $ tokenHeader ;
68+ }
69+
5970 /**
6071 * We don't have anything to do here.
6172 *
You can’t perform that action at this time.
0 commit comments