Skip to content

Commit 1ec4fa0

Browse files
committed
remove chained formatter instance from config, use string value
1 parent b725930 commit 1ec4fa0

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

config/jwt.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?php
22

3-
use Lcobucci\JWT\Encoding\ChainedFormatter;
4-
53
return [
64
// Look for a dedicated signing key, fall back to app key
75
'key' => env('JWT_SIGNING_KEY', env('APP_KEY')),
@@ -25,5 +23,5 @@
2523
'audience' => env('JWT_VALIDATE_AUDIENCE', true),
2624
],
2725

28-
'chained_formatter' => ChainedFormatter::default(),
26+
'chained_formatter' => env('JWT_CHAINED_FORMATTER', 'default'),
2927
];

src/JWTServiceProvider.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Http\Request;
66
use Illuminate\Support\ServiceProvider;
77
use Illuminate\Support\Str;
8+
use Lcobucci\JWT\Encoding\ChainedFormatter;
89

910
class 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,

tests/ClientTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

tests/ConfigTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)