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

Unable to get expiration date #1136

Closed
tobiasbp opened this issue May 28, 2024 · 3 comments
Closed

Unable to get expiration date #1136

tobiasbp opened this issue May 28, 2024 · 3 comments
Assignees

Comments

@tobiasbp
Copy link

I'm parsing a token as seen below. I'm unable to get the correct value of exp in the token header. When I inspect my token with other tools (like https://jwt.io/#debugger-io) , I see this header for the token:

{
  "ver": 2,
  "kid": "*****",
  "exp": 1716447235,
  "alg": "RS256",
  "jku": "**********"
}

Here is my demo code:

t, _ := jwt.ParseHeader(
    r.Header,
    "x-jws-signature",
    jwt.WithVerify(false),
)

fmt.Printf("%s\n", t.Expiration())

I get the following output:

0001-01-01 00:00:00 +0000 UTC
@lestrrat
Copy link
Collaborator

Without the actual token, it's hard to say. But here's what I can cob together as a minimal test case, and I can't reproduce it.

func TestGH1136(t *testing.T) {
	const src = `{
		"ver": 2,
		"kid": "*****",
		"exp": 1716447235,
		"alg": "RS256",
		"jku": "**********"
	}`

	token := jwt.New()
	require.NoError(t, json.Unmarshal([]byte(src), token), `json.Unmarshal should succeed`)

	require.NotEqual(t, token.Expiration(), time.Time{}, `token.Expiration should not be zero`)

	t.Logf("%#v", token.Expiration())
}

The above test produces this result

$ go test -run=GH1136 -v
=== RUN   TestGH1136
    jwt_test.go:1870: time.Date(2024, time.May, 23, 6, 53, 55, 0, time.UTC)
--- PASS: TestGH1136 (0.00s)
PASS
ok      github.com/lestrrat-go/jwx/v2/jwt       0.003s

I could be off, but with the test results I'm inclined to think that the token that is producing a zero time.Time is NOT the same as the token you pasted on jwt.io. I'd need more info if you're sure it's the library that is at fault.

@tobiasbp
Copy link
Author

I have realized, that the problem is that my token, has the exp in the header, not in the payload (like everyone else in the world).

Sorry for the noise, and thank you for this package.

@lestrrat
Copy link
Collaborator

no prob. thanks for getting back

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants