-
Notifications
You must be signed in to change notification settings - Fork 358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to change time precision for creation/parsing tokens. #400
Comments
I had a similar feature in mind a while ago. This was previously not possible, but recently we changed the way the parser/validator works and both can now be supplied with options that are accessible in the respective (de)serialisation functions, so this might work. You could probably take some hints from #301. Specifically you need to apply the token options to the created token like this (which is not yet in main): Just to add, I am not quite sure why, but after writing these lines I think there was still some kind of issue with this we could not work around... But I cannot remember, so feel free to try it ;) |
makes sense! Will take a crack and give and update! |
Hmm I remember now why this probably won’t work. You will not have access to the options in the unmarshal func of NumericDate. I would be interested in how you solved this problem in your workaround. |
Can Confirm, this is the issue i'm hitting against! I am mainly working with the idea to add a
But like you said, parser won't be able to control the unmarshal issue.
And registered claims being something like:
And inside the parser, we call it before getting unmarshalled i.e.
That looks like it may work, but it feels a bit wonky.
I do think adding a precision field on the NumericDate object would be a step in the right direction, as that would give us more control, but not seeing a way for the parser to control that. Curious on your thoughts! |
we are probably stuck here until the v2 version of json arrives with options. See https://pkg.go.dev/github.com/go-json-experiment/json#Options |
We can currently change the precision of timestamps getting serialized by modifying
TimePrecision
here.However we are running into an issue where we have to serialize/validate different jwt tokens of various precisions (i.e. seconds, milliseconds).
As a work around, we are creating our own version of
jwt.RegisteredClaims
that serializes/deserializes times based on the precision that we want. However it would be nice if we can include a time precision option injwt.New
orjwt.ParseWithClaims
The text was updated successfully, but these errors were encountered: