go-chi / jwtauth

JWT authentication middleware for Go HTTP services
MIT License
541 stars 91 forks source link

Specify a custom decoder #46

Closed razor-1 closed 3 years ago

razor-1 commented 4 years ago

This is mostly to support claim types other than MapClaims, but may have other uses as well. Made it a public struct member instead of changing the NewWithParser signature.

A simple example custom decoder might be:

func MyDecoder(tokenString string) (t *jwt.Token, err error) {
    t, err = jwt.ParseWithClaims(tokenString, &MyCustomClaims{}, func(token *jwt.Token) (interface{}, error) {
        return []byte("mysecretkey"), nil
    })
    return
}
razor-1 commented 4 years ago

Are PRs accepted here? any feedback on this? thank you