Skip to content

Commit 0aa5cff

Browse files
authored
Update JWT.php
1 parent a538a1a commit 0aa5cff

File tree

1 file changed

+22
-1
lines changed
  • src/Authentication/Authenticators

1 file changed

+22
-1
lines changed

src/Authentication/Authenticators/JWT.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace CodeIgniter\Shield\Authentication\Authenticators;
1515

1616
use CodeIgniter\HTTP\IncomingRequest;
17+
use CodeIgniter\HTTP\RequestInterface;
1718
use CodeIgniter\I18n\Time;
1819
use CodeIgniter\Shield\Authentication\AuthenticationException;
1920
use 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
*/

0 commit comments

Comments
 (0)