Skip to content

Struggle to understand JWKS Cache #957

Answered by BigBoulard
BigBoulard asked this question in Q&A
Discussion options

You must be logged in to vote

Thank you for your prompt and detailed answer.

I think I got it, let's see...

  • Here the intent of the call to Refresh is just to verify that the cache system is working, but we don't need to use the jwk.Set yet
    _, err := c.Refresh(ctx, googleCerts)

  • On the other hand, the following line returns the jwk.Set I can use directly in my program without having to call any kind of function. The value of cached is automatically updated under the hood by your program.
    cached := jwk.NewCachedSet(c, googleCerts)

... from there, any time I need to parse and verify a token, I can use cached like below:

tok, err := jwt.Parse(
    serialized,
    jwt.WithKeySet(cached), // <<<<
  )
  if err != nil {
…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@BigBoulard
Comment options

Answer selected by BigBoulard
@lestrrat
Comment options

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants