Skip to content

Commit

Permalink
fix: use short classname for config()
Browse files Browse the repository at this point in the history
If FQCN is specified, devs cannot override.
  • Loading branch information
kenjis committed Aug 24, 2023
1 parent 970c67e commit 23286e1
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 8 deletions.
8 changes: 5 additions & 3 deletions src/Authentication/Authenticators/JWT.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public function __construct(UserModel $provider)
*/
public function attempt(array $credentials): Result
{
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');

/** @var IncomingRequest $request */
$request = service('request');
Expand Down Expand Up @@ -142,7 +143,7 @@ public function check(array $credentials): Result
'success' => false,
'reason' => lang(
'Auth.noToken',
[config(AuthJWT::class)->authenticatorHeader]
[config('AuthJWT')->authenticatorHeader]
),
]);
}
Expand Down Expand Up @@ -196,7 +197,8 @@ public function loggedIn(): bool
/** @var IncomingRequest $request */
$request = service('request');

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');

return $this->attempt([
'token' => $request->getHeaderLine($config->authenticatorHeader),
Expand Down
6 changes: 4 additions & 2 deletions src/Authentication/JWT/Adapters/FirebaseAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public function decode(string $encodedToken, $keyset): stdClass
*/
private function createKeysForDecode($keyset)
{
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');

$configKeys = $config->keys[$keyset];

Expand Down Expand Up @@ -127,7 +128,8 @@ public function encode(array $payload, $keyset, ?array $headers = null): string
*/
private function createKeysForEncode($keyset): array
{
$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');

if (isset($config->keys[$keyset][0]['secret'])) {
$key = $config->keys[$keyset][0]['secret'];
Expand Down
3 changes: 2 additions & 1 deletion src/Authentication/JWT/JWSEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public function encode(
'Cannot pass $claims[\'exp\'] and $ttl at the same time.'
);

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');

$payload = array_merge(
$config->defaultClaims,
Expand Down
3 changes: 2 additions & 1 deletion src/Filters/JWTAuth.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ private function getTokenFromHeader(RequestInterface $request): string
{
assert($request instanceof IncomingRequest);

$config = config(AuthJWT::class);
/** @var AuthJWT $config */
$config = config('AuthJWT');

$tokenHeader = $request->getHeaderLine(
$config->authenticatorHeader ?? 'Authorization'
Expand Down
2 changes: 1 addition & 1 deletion src/Models/BaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ abstract class BaseModel extends Model

public function __construct()
{
$this->authConfig = config(Auth::class);
$this->authConfig = config('Auth');

if ($this->authConfig->DBGroup !== null) {
$this->DBGroup = $this->authConfig->DBGroup;
Expand Down

0 comments on commit 23286e1

Please sign in to comment.