File tree Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Expand file tree Collapse file tree 4 files changed +18
-5
lines changed Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
- use Lcobucci \JWT \Encoding \ChainedFormatter ;
4
-
5
3
return [
6
4
// Look for a dedicated signing key, fall back to app key
7
5
'key ' => env ('JWT_SIGNING_KEY ' , env ('APP_KEY ' )),
25
23
'audience ' => env ('JWT_VALIDATE_AUDIENCE ' , true ),
26
24
],
27
25
28
- 'chained_formatter ' => ChainedFormatter:: default ( ),
26
+ 'chained_formatter ' => env ( ' JWT_CHAINED_FORMATTER ' , ' default ' ),
29
27
];
Original file line number Diff line number Diff line change 5
5
use Illuminate \Http \Request ;
6
6
use Illuminate \Support \ServiceProvider ;
7
7
use Illuminate \Support \Str ;
8
+ use Lcobucci \JWT \Encoding \ChainedFormatter ;
8
9
9
10
class JWTServiceProvider extends ServiceProvider
10
11
{
@@ -37,7 +38,12 @@ public function register(): void
37
38
}
38
39
39
40
$ signer = config ('jwt.signer ' );
40
- $ chainedFormatter = config ('jwt.chained_formatter ' );
41
+
42
+ $ chainedFormatter = match (true ) {
43
+ config ('jwt.chained_formatter ' ) instanceof ChainedFormatter => config ('jwt.chained_formatter ' ),
44
+ config ('jwt.chained_formatter ' ) === "unix " => ChainedFormatter::withUnixTimestampDates (),
45
+ default => ChainedFormatter::default ()
46
+ };
41
47
42
48
return new Client (
43
49
$ key ,
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ protected function getEnvironmentSetUp($app): void
34
34
'issuer ' => 'myappiss ' ,
35
35
'lifetime ' => 900 ,
36
36
'signer ' => \Lcobucci \JWT \Signer \Hmac \Sha256::class,
37
- 'chained_formatter ' => ChainedFormatter:: default () ,
37
+ 'chained_formatter ' => " default " ,
38
38
]]);
39
39
}
40
40
Original file line number Diff line number Diff line change @@ -32,4 +32,13 @@ public function testSigningKeyWithExplicitJwtKey()
32
32
33
33
$ this ->assertEquals ('thisisjwtkey ' , config ('jwt.key ' ));
34
34
}
35
+
36
+ public function testChainedFormatter ()
37
+ {
38
+ putenv ('JWT_CHAINED_FORMATTER=unix ' );
39
+
40
+ $ this ->refreshApplication ();
41
+
42
+ $ this ->assertEquals ('unix ' , config ('jwt.chained_formatter ' ));
43
+ }
35
44
}
You can’t perform that action at this time.
0 commit comments