File tree Expand file tree Collapse file tree 5 files changed +16
-10
lines changed
Expand file tree Collapse file tree 5 files changed +16
-10
lines changed Original file line number Diff line number Diff line change @@ -25,16 +25,16 @@ public function formatClaims(array $claims): array
2525 return $ claims ;
2626 }
2727
28- /** @return int|string */
28+ /** @return int|float */
2929 private function convertDate (DateTimeImmutable $ date )
3030 {
31- $ seconds = $ date ->format ('U ' );
31+ $ timestamp = $ date ->format ('U.u ' );
3232 $ microseconds = $ date ->format ('u ' );
3333
3434 if ((int ) $ microseconds === 0 ) {
35- return (int ) $ seconds ;
35+ return (int ) $ timestamp ;
3636 }
3737
38- return $ seconds . ' . ' . $ microseconds ;
38+ return ( float ) $ timestamp ;
3939 }
4040}
Original file line number Diff line number Diff line change 1212use function count ;
1313use function explode ;
1414use function is_array ;
15+ use function is_string ;
16+ use function json_encode ;
1517use function strpos ;
1618
19+ use const JSON_THROW_ON_ERROR ;
20+
1721final class Parser implements ParserInterface
1822{
1923 private Decoder $ decoder ;
@@ -105,7 +109,9 @@ private function parseClaims(string $data): array
105109 continue ;
106110 }
107111
108- $ claims [$ claim ] = $ this ->convertDate ((string ) $ claims [$ claim ]);
112+ $ date = $ claims [$ claim ];
113+
114+ $ claims [$ claim ] = $ this ->convertDate (is_string ($ date ) ? $ date : json_encode ($ date , JSON_THROW_ON_ERROR ));
109115 }
110116
111117 return $ claims ;
Original file line number Diff line number Diff line change @@ -34,6 +34,6 @@ public function formatClaimsShouldApplyAllConfiguredFormatters(): void
3434 $ formatted = $ formatter ->formatClaims ($ claims );
3535
3636 self ::assertSame ('test ' , $ formatted [RegisteredClaims::AUDIENCE ]);
37- self ::assertSame (' 1487285080.123456 ' , $ formatted [RegisteredClaims::EXPIRATION_TIME ]);
37+ self ::assertSame (1487285080.123456 , $ formatted [RegisteredClaims::EXPIRATION_TIME ]);
3838 }
3939}
Original file line number Diff line number Diff line change @@ -36,8 +36,8 @@ public function dateClaimsHaveMicrosecondsOrSeconds(): void
3636 $ formatted = $ formatter ->formatClaims ($ claims );
3737
3838 self ::assertSame (1487285080 , $ formatted [RegisteredClaims::ISSUED_AT ]);
39- self ::assertSame (' 1487285080.000123 ' , $ formatted [RegisteredClaims::NOT_BEFORE ]);
40- self ::assertSame (' 1487285080.123456 ' , $ formatted [RegisteredClaims::EXPIRATION_TIME ]);
39+ self ::assertSame (1487285080.000123 , $ formatted [RegisteredClaims::NOT_BEFORE ]);
40+ self ::assertSame (1487285080.123456 , $ formatted [RegisteredClaims::EXPIRATION_TIME ]);
4141 self ::assertSame ('test ' , $ formatted ['testing ' ]); // this should remain untouched
4242 }
4343
@@ -62,7 +62,7 @@ public function notAllDateClaimsNeedToBeConfigured(): void
6262 $ formatted = $ formatter ->formatClaims ($ claims );
6363
6464 self ::assertSame (1487285080 , $ formatted [RegisteredClaims::ISSUED_AT ]);
65- self ::assertSame (' 1487285080.123456 ' , $ formatted [RegisteredClaims::EXPIRATION_TIME ]);
65+ self ::assertSame (1487285080.123456 , $ formatted [RegisteredClaims::EXPIRATION_TIME ]);
6666 self ::assertSame ('test ' , $ formatted ['testing ' ]); // this should remain untouched
6767 }
6868}
Original file line number Diff line number Diff line change @@ -453,7 +453,7 @@ public function parseMustConvertDateClaimsToObjects(): void
453453 {
454454 $ data = [
455455 RegisteredClaims::ISSUED_AT => 1486930663 ,
456- RegisteredClaims::EXPIRATION_TIME => ' 1486930757.023055 ' ,
456+ RegisteredClaims::EXPIRATION_TIME => 1486930757.023055 ,
457457 ];
458458
459459 $ this ->decoder ->expects (self ::exactly (2 ))
You can’t perform that action at this time.
0 commit comments