Closed snago closed 1 year ago
Oh, there's some interaction with the other PR that was just merged. I'll take a look at that and make sure that order is preserved for the new JSON-string methods as well...
Fixed! All that was needed was to use LinkedHashMap
in those methods as well.
I made the unit test check the result of JSON claims as well, in both header and payload.
Changes
Make header and payload fields in the resulting JWT have the same order as they were added to the
JWTCreator.Builder
. When looking at a decoded JWT it's easier to see if all expected claims are included when they aren't scrambled.Very small change, only changed
HashMap
toLinkedHashMap
forheaderClaims
andpayloadClaims
inJWTCreator.Builder
.A more complicated variant could allow selection of different orderings, e.g.
scrambled
(current),insertion order
(this) andalphabetically sorted
(e.g. by usingTreeMap
).Order was unspecified before (since
HashMap
was used), now it's deterministic.References
None that I know of.
Testing
I've added a test that verifies that both header and payload claims are in insertion order. The test doesn't care about where any other header fields are inserted, such as
alg
ortyp
(they will be last since they're added in thesign
method).Checklist