DEV Community

Discussion on: A Simple JWT Go Package

Collapse
 
martip07 profile image
Joseph Paz

Hi, awsome.

Let me give it a try. Btw, how do you manage the invalidation of the tokens?

Collapse
 
jrpalma profile image
Jose Palma

Hi Joseph, thanks for your question.
TLDR
I modified the API. Please refresh your clone/fork. To invalidate your token, you can do something like this:

//Issue the token
token.Claims.Set("valid", true)
token.Sign("secret")

//Invalidate the token
token.Claims.Set("valid", false)
token.Sign("secret")

//Check if valid
verifyErr := token.Verify(base64JWT, "secret")
if verifyErr != nil {
    //Tampered token
}
valid, err := token.Claims.GetBool("valid")
if err != nil {
    //Error getting claim
}
if !valid {
    //Invalid token logic goes here
}

Long Story:
I wrote this package a couple of years ago while learning about JWT. I open-sourced the code. However, I made a mistake and used map[string]string instead of map[string]interface{}. Thanks your question, I realized that I had made a mistake. I updated the API to include some helper functions for bool, time, []byte, string, and numbers. I really appreciate your input. I will start thinking about its first release soon. Do let me know if you have more questions. That might lead to more features on the first release. Thanks!

Collapse
 
martip07 profile image
Joseph Paz

Great, let check it. I will tell you soon :D