File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
src/Authentication/Authenticators Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change 1414namespace CodeIgniter \Shield \Authentication \Authenticators ;
1515
1616use CodeIgniter \HTTP \IncomingRequest ;
17+ use CodeIgniter \HTTP \RequestInterface ;
1718use CodeIgniter \I18n \Time ;
1819use CodeIgniter \Shield \Authentication \AuthenticationException ;
1920use CodeIgniter \Shield \Authentication \AuthenticatorInterface ;
@@ -209,11 +210,31 @@ public function loggedIn(): bool
209210 /** @var AuthJWT $config */
210211 $ config = config ('AuthJWT ' );
211212
213+ $ token = $ this ->getTokenFromHeader ($ request );
214+
212215 return $ this ->attempt ([
213- 'token ' => $ request -> getHeaderLine ( $ config -> authenticatorHeader ) ,
216+ 'token ' => $ token ,
214217 ])->isOK ();
215218 }
216219
220+ private function getTokenFromHeader (RequestInterface $ request ): string
221+ {
222+ assert ($ request instanceof IncomingRequest);
223+
224+ /** @var AuthJWT $config */
225+ $ config = config ('AuthJWT ' );
226+
227+ $ tokenHeader = $ request ->getHeaderLine (
228+ $ config ->authenticatorHeader ?? 'Authorization '
229+ );
230+
231+ if (strpos ($ tokenHeader , 'Bearer ' ) === 0 ) {
232+ return trim (substr ($ tokenHeader , 6 ));
233+ }
234+
235+ return $ tokenHeader ;
236+ }
237+
217238 /**
218239 * Logs the given user in by saving them to the class.
219240 */
You can’t perform that action at this time.
0 commit comments