Skip to content

Commit b74d082

Browse files
committed
refactor: remove JWTAuth::getTokenFromHeader() and use JWT::getTokenFromHeader()
1 parent 0aa5cff commit b74d082

File tree

2 files changed

+2
-24
lines changed

2 files changed

+2
-24
lines changed

src/Authentication/Authenticators/JWT.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,17 +207,14 @@ public function loggedIn(): bool
207207
/** @var IncomingRequest $request */
208208
$request = service('request');
209209

210-
/** @var AuthJWT $config */
211-
$config = config('AuthJWT');
212-
213210
$token = $this->getTokenFromHeader($request);
214211

215212
return $this->attempt([
216213
'token' => $token,
217214
])->isOK();
218215
}
219216

220-
private function getTokenFromHeader(RequestInterface $request): string
217+
public function getTokenFromHeader(RequestInterface $request): string
221218
{
222219
assert($request instanceof IncomingRequest);
223220

src/Filters/JWTAuth.php

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
use CodeIgniter\HTTP\Response;
2020
use CodeIgniter\HTTP\ResponseInterface;
2121
use CodeIgniter\Shield\Authentication\Authenticators\JWT;
22-
use CodeIgniter\Shield\Config\AuthJWT;
2322
use Config\Services;
2423

2524
/**
@@ -45,7 +44,7 @@ public function before(RequestInterface $request, $arguments = null)
4544
/** @var JWT $authenticator */
4645
$authenticator = auth('jwt')->getAuthenticator();
4746

48-
$token = $this->getTokenFromHeader($request);
47+
$token = $authenticator->getTokenFromHeader($request);
4948

5049
$result = $authenticator->attempt(['token' => $token]);
5150

@@ -62,24 +61,6 @@ public function before(RequestInterface $request, $arguments = null)
6261
}
6362
}
6463

65-
private function getTokenFromHeader(RequestInterface $request): string
66-
{
67-
assert($request instanceof IncomingRequest);
68-
69-
/** @var AuthJWT $config */
70-
$config = config('AuthJWT');
71-
72-
$tokenHeader = $request->getHeaderLine(
73-
$config->authenticatorHeader ?? 'Authorization'
74-
);
75-
76-
if (strpos($tokenHeader, 'Bearer') === 0) {
77-
return trim(substr($tokenHeader, 6));
78-
}
79-
80-
return $tokenHeader;
81-
}
82-
8364
/**
8465
* We don't have anything to do here.
8566
*

0 commit comments

Comments
 (0)