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 11<?php
22
3- use Lcobucci \JWT \Encoding \ChainedFormatter ;
4-
53return [
64 // Look for a dedicated signing key, fall back to app key
75 'key ' => env ('JWT_SIGNING_KEY ' , env ('APP_KEY ' )),
2523 'audience ' => env ('JWT_VALIDATE_AUDIENCE ' , true ),
2624 ],
2725
28- 'chained_formatter ' => ChainedFormatter:: default ( ),
26+ 'chained_formatter ' => env ( ' JWT_CHAINED_FORMATTER ' , ' default ' ),
2927];
Original file line number Diff line number Diff line change 55use Illuminate \Http \Request ;
66use Illuminate \Support \ServiceProvider ;
77use Illuminate \Support \Str ;
8+ use Lcobucci \JWT \Encoding \ChainedFormatter ;
89
910class JWTServiceProvider extends ServiceProvider
1011{
@@ -37,7 +38,12 @@ public function register(): void
3738 }
3839
3940 $ 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+ };
4147
4248 return new Client (
4349 $ key ,
Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ protected function getEnvironmentSetUp($app): void
3434 'issuer ' => 'myappiss ' ,
3535 'lifetime ' => 900 ,
3636 'signer ' => \Lcobucci \JWT \Signer \Hmac \Sha256::class,
37- 'chained_formatter ' => ChainedFormatter:: default () ,
37+ 'chained_formatter ' => " default " ,
3838 ]]);
3939 }
4040
Original file line number Diff line number Diff line change @@ -32,4 +32,13 @@ public function testSigningKeyWithExplicitJwtKey()
3232
3333 $ this ->assertEquals ('thisisjwtkey ' , config ('jwt.key ' ));
3434 }
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+ }
3544}
You can’t perform that action at this time.
0 commit comments