Skip to content

Commit 7b6c44f

Browse files
committed
upgrading
1 parent eea5597 commit 7b6c44f

3 files changed

Lines changed: 8 additions & 14 deletions

File tree

UPGRADING.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,16 @@ If you use the JWT authenticator with an HMAC algorithm (`HS256`, `HS384`, or
88
`HS512`), the underlying `firebase/php-jwt` library was upgraded to v7, which
99
now enforces minimum key lengths at runtime.
1010

11-
| Algorithm | Minimum secret length |
12-
|-----------|-----------------------|
13-
| HS256 | 32 bytes (256 bits) |
14-
| HS384 | 48 bytes (384 bits) |
15-
| HS512 | 64 bytes (512 bits) |
11+
| Algorithm | Minimum secret length | Command to generate |
12+
|-----------|-----------------------|---------------------------------------------------|
13+
| HS256 | 32 bytes (256 bits) | `php -r 'echo base64_encode(random_bytes(32));'` |
14+
| HS384 | 48 bytes (384 bits) | `php -r 'echo base64_encode(random_bytes(48));'` |
15+
| HS512 | 64 bytes (512 bits) | `php -r 'echo base64_encode(random_bytes(64));'` |
1616

1717
If your secret is too short, every JWT encode **and** decode call will throw a
1818
`LogicException` with the message `Cannot encode/decode JWT: Provided key is too short`.
1919

20-
To generate a valid secret, run:
21-
22-
```console
23-
php -r 'echo base64_encode(random_bytes(32));'
24-
```
25-
26-
Then update `$keys` in **app/Config/AuthJWT.php**:
20+
Run the command for your algorithm, then update `$keys` in **app/Config/AuthJWT.php**:
2721

2822
```php
2923
'secret' => '<output of the command above>',

src/Config/AuthJWT.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AuthJWT extends BaseConfig
5858
[
5959
'kid' => '', // Key ID. Optional if you have only one key.
6060
'alg' => 'HS256', // algorithm.
61-
// Set secret random string. Needs at least 256 bits for HS256 algorithm.
61+
// Set secret random string. Needs at least 256/384/512 bits for HS256/HS384/HS512.
6262
// E.g., $ php -r 'echo base64_encode(random_bytes(32));'
6363
'secret' => '<Set secret random string>',
6464
],

tests/_support/TestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function setUp(): void
5252
$config->csrfProtection = 'session';
5353
Factories::injectMock('config', 'Security', $config);
5454

55-
// Set a valid JWT secret ( 256 bits for HS256) required by firebase/php-jwt v7
55+
// Set a valid JWT secret (>= 256 bits for HS256) required by firebase/php-jwt v7
5656
$config = config('AuthJWT');
5757
$config->keys['default'][0]['secret'] = 'a-very-secure-secret-key-for-hs256-ok';
5858
Factories::injectMock('config', 'AuthJWT', $config);

0 commit comments

Comments
 (0)