Search code examples
gojwtjwt-go

How to get to get claims from JWT token without validation in Go


I have a JWT token with the claims below

{
  "authorized": true,
  "email": "[email protected]",
  "exp": 1589929351,
  "node": "/auth/nodes0000000023",
  "role": "admin"
}

The issuer of the JWT is the claims['node']. In the above claims it is the /auth/nodes0000000023. How do I extract the issuer from the token without verifying the token. I want to get the issuer name so that I can go find his publicKey from a map and then verify the token.

I have found the function func (*Parser) ParseUnverified in the docs, but it is unclear on how to use it.

The library used is github.com/dgrijalva/jwt-go


Solution

  • You can use the unverified parse API the same way you use the verified API:

    tok,_,err := p.ParseUnverified(tokenString,&claimsStruct)