Is jwtauth to validate jwt ? or can I create new jwt tokens using jwtauth?
mahesh-riddles opened this issue · 1 comments
Hi
`tokenAuth = jwtauth.New("HS256", []byte("secret"), nil)
// For debugging/example purposes, we generate and print
// a sample jwt token with claims `user_id:123` here:
_, tokenString, _ := tokenAuth.Encode(map[string]interface{}{"user_id": 123})
fmt.Printf("DEBUG: a sample jwt is %s\n\n", tokenString)`
From this example, it seems I can create new JWT token.
But how do I give expiry date/time and other details?
hi there, jwtauth is a jwt authentication library built on top of github.com/lestrrat-go/jwx/v2 (see https://github.com/go-chi/jwtauth/blob/master/go.mod#L7) which gives you a jwt auth middleware handler and few extra helper methods.
you can generate JWT tokens with any JWT compatible library, including jwx/v2, or with jwtauth as well.
See https://github.com/go-chi/jwtauth/blob/master/_example/main.go#L78 for how to generate a jwt token with jwtauth.
for validation, see https://github.com/go-chi/jwtauth/blob/master/_example/main.go#L93-L100