Skip to content

Commit 55a2cb4

Browse files
committed
refactor: move JWT authenticatorHeader setting to Config\AuthJWT
1 parent af20960 commit 55a2cb4

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

src/Authentication/Authenticators/JWT.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,11 @@ public function loggedIn(): bool
169169
/** @var IncomingRequest $request */
170170
$request = service('request');
171171

172+
/** @var AuthJWT $config */
173+
$config = config('AuthJWT');
174+
172175
return $this->attempt([
173-
'token' => $request->getHeaderLine(config('Auth')->authenticatorHeader['jwt']),
176+
'token' => $request->getHeaderLine($config->authenticatorHeader),
174177
])->isOK();
175178
}
176179

src/Config/Auth.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ class Auth extends BaseConfig
9999
*/
100100
public array $authenticatorHeader = [
101101
'tokens' => 'Authorization',
102-
'jwt' => 'Authorization',
103102
];
104103

105104
/**

src/Config/AuthJWT.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@
1111
*/
1212
class AuthJWT extends BaseConfig
1313
{
14+
/**
15+
* --------------------------------------------------------------------
16+
* Name of Authenticator Header
17+
* --------------------------------------------------------------------
18+
* The name of Header that the Authorization token should be found.
19+
* According to the specs, this should be `Authorization`, but rare
20+
* circumstances might need a different header.
21+
*/
22+
public string $authenticatorHeader = 'Authorization';
23+
1424
/**
1525
* The payload items that all JWT have.
1626
*

src/Filters/JWTAuth.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use CodeIgniter\HTTP\Response;
1111
use CodeIgniter\HTTP\ResponseInterface;
1212
use CodeIgniter\Shield\Authentication\Authenticators\JWT;
13+
use CodeIgniter\Shield\Config\AuthJWT;
1314
use Config\Services;
1415

1516
/**
@@ -65,8 +66,11 @@ private function getTokenFromHeader(RequestInterface $request): string
6566
{
6667
assert($request instanceof IncomingRequest);
6768

69+
/** @var AuthJWT $config */
70+
$config = config('AuthJWT');
71+
6872
$tokenHeader = $request->getHeaderLine(
69-
setting('Auth.authenticatorHeader')['jwt'] ?? 'Authorization'
73+
$config->authenticatorHeader ?? 'Authorization'
7074
);
7175

7276
if (strpos($tokenHeader, 'Bearer') === 0) {

0 commit comments

Comments
 (0)