Skip to content
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

json: cannot unmarshal string into Go struct field claims.iat of type int64 #404

Closed
norkunas opened this issue Nov 27, 2020 · 7 comments · Fixed by #491
Closed

json: cannot unmarshal string into Go struct field claims.iat of type int64 #404

norkunas opened this issue Nov 27, 2020 · 7 comments · Fixed by #491
Labels
pinned The issue must not be marked as stale

Comments

@norkunas
Copy link

When building jwt with new lcobucci/jwt lib version I get this error.
Looking at it's source if datetime supports miliseconds then it appends it.
This lib expects datetime instances:

$now = new DateTimeImmutable();
$expires = $now->modify('+1 hour');       
$jwtToken = $configuration->builder()
            ->issuedAt($now)
            ->expiresAt($expires)
            ...

When trying to use withClaim manually with "iat" or "exp" it throws error: "Builder#withClaim() is meant to be used for non-registered claims, check the documentation on how to set claim "iat".

So my question is should mercure support these claims with miliseconds?

@dunglas
Copy link
Owner

dunglas commented Nov 28, 2020

This should probably be reported to the underlying JWT library we use in Mercure? WDYT? http://github.com/form3tech-oss/jwt-go

@chalasr
Copy link
Contributor

chalasr commented Nov 29, 2020

As per https://tools.ietf.org/html/draft-ietf-oauth-json-web-token-32#section-2, the jwt-go library should indeed support strings for date/time fields:

NumericDate This is equivalent to the IEEE Std 1003.1,
2013 Edition [POSIX.1] definition "Seconds Since the Epoch", in
which each day is accounted for by exactly 86400 seconds, other
than that non-integer values can be represented. See RFC 3339
[RFC3339] for details regarding date/times in general and UTC in
particular.

I'll propose a fix there when I have some free time (but feel free to report/fix it before).
Meanwhile, here is a one-class workaround to make lcobucci/jwt v4 compatible with it: https://gist.github.com/chalasr/7fe121992bd125f2313619aff447df5f

@norkunas
Copy link
Author

Thanks @chalasr :)

@stale
Copy link

stale bot commented Jan 29, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added wontfix This will not be worked on and removed wontfix This will not be worked on labels Jan 29, 2021
@stale
Copy link

stale bot commented Mar 30, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Mar 30, 2021
@dunglas dunglas added the pinned The issue must not be marked as stale label Apr 1, 2021
@stale stale bot removed the wontfix This will not be worked on label Apr 1, 2021
@garak
Copy link

garak commented Apr 30, 2021

Is there any chance that fix can be backported to the legacy version (e.g. v0.10)?

@dunglas
Copy link
Owner

dunglas commented Aug 2, 2021

@garak use the "legacy" build that we provide for newer versions. It contains the fix and is compatible with the legacy configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinned The issue must not be marked as stale
Projects
None yet
4 participants