Skip to content

Commit dcbdb28

Browse files
committed
config: comment out jwt authenticator
It is an optional authenticator.
1 parent 72047b7 commit dcbdb28

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

docs/addons/jwt.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,35 @@ To use JWT Authentication, you need additional setup and configuration.
5252

5353
3. If your **app/Config/Auth.php** is not up-to-date, you also need to update it. Check **vendor/codeigniter4/shield/src/Config/Auth.php** and apply the differences.
5454

55+
You need to add the following constants:
56+
```php
57+
public const RECORD_LOGIN_ATTEMPT_NONE = 0; // Do not record at all
58+
public const RECORD_LOGIN_ATTEMPT_FAILURE = 1; // Record only failures
59+
public const RECORD_LOGIN_ATTEMPT_ALL = 2; // Record all login attempts
60+
```
61+
62+
You need to add JWT Authenticator:
63+
```php
64+
use CodeIgniter\Shield\Authentication\Authenticators\JWT;
65+
66+
// ...
67+
68+
public array $authenticators = [
69+
'tokens' => AccessTokens::class,
70+
'session' => Session::class,
71+
'jwt' => JWT::class,
72+
];
73+
```
74+
75+
If you want to use JWT Authenticator in Authentication Chain, add `jwt`:
76+
```php
77+
public array $authenticationChain = [
78+
'session',
79+
'tokens',
80+
'jwt'
81+
];
82+
```
83+
5584
## Configuration
5685

5786
Configure **app/Config/AuthJWT.php** for your needs.

src/Config/Auth.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class Auth extends BaseConfig
127127
public array $authenticators = [
128128
'tokens' => AccessTokens::class,
129129
'session' => Session::class,
130-
'jwt' => JWT::class,
130+
// 'jwt' => JWT::class,
131131
];
132132

133133
/**
@@ -174,6 +174,7 @@ class Auth extends BaseConfig
174174
public array $authenticationChain = [
175175
'session',
176176
'tokens',
177+
// 'jwt',
177178
];
178179

179180
/**

tests/Authentication/Authenticators/JWTAuthenticatorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ protected function setUp(): void
3434
{
3535
parent::setUp();
3636

37-
$config = new Auth();
38-
$auth = new Authentication($config);
37+
$config = new Auth();
38+
$config->authenticators['jwt'] = JWT::class;
39+
40+
$auth = new Authentication($config);
3941
$auth->setProvider(\model(UserModel::class));
4042

4143
/** @var JWT $authenticator */

tests/Authentication/Filters/JWTFilterTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
namespace Tests\Authentication\Filters;
66

77
use CodeIgniter\Config\Factories;
8+
use CodeIgniter\Shield\Authentication\Authenticators\JWT;
89
use CodeIgniter\Shield\Authentication\JWTManager;
10+
use CodeIgniter\Shield\Config\Auth;
911
use CodeIgniter\Shield\Entities\User;
1012
use CodeIgniter\Shield\Filters\JWTAuth;
1113
use CodeIgniter\Shield\Models\UserModel;
@@ -30,6 +32,10 @@ protected function setUp(): void
3032

3133
$_SESSION = [];
3234

35+
// Add JWT Authenticator
36+
$config = config(Auth::class);
37+
$config->authenticators['jwt'] = JWT::class;
38+
3339
// Register our filter
3440
$filterConfig = \config('Filters');
3541
$filterConfig->aliases['jwtAuth'] = JWTAuth::class;

0 commit comments

Comments
 (0)