Questions tagged [jwt-go]

59 questions
42
votes
5 answers

How to decode a JWT token in Go?

I am currently working on a Go application. I receive a JWT token from the client side and I need to decode that token and obtain the relevant information: user, name, etc. I was checking the libraries that are available to handle JWT tokens and I…
Sredny M Casanova
  • 4,735
  • 21
  • 70
  • 115
29
votes
3 answers

How to verify JWT signature with JWK in Go?

I have been searching for an example I can understand of how to validate the signature of a JWT with the Go Language. This might be especially tricky since I am using Okta, and it uses JWKs, so it is not especially straight forward. When I receive a…
user3888307
  • 2,825
  • 5
  • 22
  • 32
27
votes
5 answers

How to extract and verify token sent from frontend

I am using "github.com/dgrijalva/jwt-go", and able to send a token to my frontend, and what I would like to know how I could retrieve the token sent from the frontend so that I can verify if the token that was sent is valid and if so the secured…
poise
  • 817
  • 1
  • 9
  • 16
25
votes
4 answers

Go and JWT - Simple authentication

I'm currently making an API (with go) and I'm working on the session part. After research about what to use for session, I found JWT really interesting. However I'm not really sure to understand how to use it after some tutorials. So this is my…
Emixam23
  • 3,854
  • 8
  • 50
  • 107
19
votes
2 answers

How to extract the claims from JWT token

I'm using the dgrijalva/jwt-go/ package. I would like to extract the payload from the token, and I couldn't find a way to do it. Example (taken from : https://jwt.io/): for…
user2212726
  • 1,225
  • 3
  • 16
  • 23
13
votes
7 answers

How to verify a JWT Token from AWS Cognito in Go?

How can I validate and get info from a JWT received from Amazon Cognito? I have setup Google authentication in Cognito, and set the redirect uri to to hit API Gateway, I then receive a code which I POST to this…
Lewis Lebentz
  • 817
  • 4
  • 13
  • 24
11
votes
2 answers

I have a public key and a JWT, how do I check if it's valid in Go?

I have a public key from my identity provider -----BEGIN PUBLIC KEY----- THIS -----END PUBLIC KEY----- And a JWT token from my client. How do I check the token against the key? I'm having difficulty with jwt-go because the Parse function takes the…
David Alsh
  • 6,747
  • 6
  • 34
  • 60
9
votes
1 answer

How to parse the expiration date of a JWT to a time.Time() in Go?

I'd like to parse the expiration date (exp) from a JSON Web Token (JWT) without verifying it. I've tried the following script (in an attempt to follow How to parse unix timestamp to time.Time): package main import ( "fmt" "log" …
Kurt Peek
  • 52,165
  • 91
  • 301
  • 526
9
votes
1 answer

How to verify a JSON Web Token with the jwt-go library?

I am using the jwt-go library in golang, and using the HS512 algorithm for signing the token. I want to make sure the token is valid and the example in the docs is like this: token, err := jwt.Parse(myToken, func(token *jwt.Token) (interface{},…
zola
  • 5,737
  • 8
  • 33
  • 48
9
votes
2 answers

go and parsing token with jwt-go

Could anyone tell me why the following (from https://github.com/dgrijalva/jwt-go) example doesn't work? token, err := jwt.Parse(myToken, func(token *jwt.Token) ([]byte, error) { return myLookupKey(token.Header["kid"]) }) if err == nil &&…
QlliOlli
  • 637
  • 3
  • 13
  • 25
8
votes
2 answers

make jwt encode faster

I have a /token endpoint that is working with a password grant. Because it's encoding a JWT token, it has high latency of about 1 second. Is there a way to make signing the JWT faster? I'm using Go with the github.com/dgrijalva/jwt-go…
slifer2015
  • 682
  • 6
  • 12
8
votes
3 answers

JWT validation with JWKS golang

Im using dgrijalva/jwt-go & lestrrat-go/jwx. What im trying to achive is validate wso2 jwt using jwks. the token(expired token): const tokenStr =…
Matankila
  • 101
  • 2
  • 12
8
votes
5 answers

Using jwt-go Library - Key is invalid or invalid type

I am trying to pass in a token to the "Parse(token String, keyFunc Keyfunc)" GO routine defined in this GO-library (http://godoc.org/github.com/dgrijalva/jwt-go) for JWT-token parsing/validation. When I pass the token to this function - token, err…
psbits
  • 1,787
  • 5
  • 19
  • 34
5
votes
2 answers

How to validate a JWT token in Golang

I want to check if a JWT is generated from our server or not? I use JWT to authenticate and use RS256 as ALGORITHM for our JWT For now, I want to write a function in Golang to validate a JWT token is ours or not. Below is code i have implement: …
Tho Quach
  • 1,347
  • 10
  • 26
5
votes
1 answer

dgrijalva/jwt-go can cast claims to MapClaims but not StandardClaims?

I am creating the token with the following code token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.StandardClaims{ Subject: string(user.Id), }) tokenString, err := token.SignedString([]byte("secret")) and trying to parse them with the…
Jamie Davenport
  • 351
  • 3
  • 10
1
2 3 4