Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow parsing with claims #46

Closed
wants to merge 1 commit into from
Closed

allow parsing with claims #46

wants to merge 1 commit into from

Conversation

butonic
Copy link

@butonic butonic commented Nov 8, 2017

so we can use

type MyCustomClaims struct {
	User string 	`json:"user"`
	*jwt.StandardClaims
}

func JWTMiddleware(h http.Handler) http.Handler {
	return jwtmiddleware.New(jwtmiddleware.Options{
		ValidationKeyGetter: func(token *jwt.Token) (interface{}, error) {
			secret := viper.GetString("jwt.secret");
			return []byte(secret), nil
		},
		UserProperty: "payload",
		SigningMethod: jwt.SigningMethodHS256,
		Claims: &MyCustomClaims{}, // pass your CustomClaims here
	}).Handler(h)
}

allows parsing timestamp as int64 ... not float

@oliverbestmann
Copy link

If i am not mistaken, you are sharing the same Claim instance for multiple requests. So if a second requests comes in while the first one is being processed, the Claims of the first request are updated in-place.

@grounded042
Copy link
Contributor

I apologize for the inactivity here. As I mentioned in #53 we are beginning work on a v2 and this is something we can look at. Note that the package we settle on to replace jwt-go might impact how custom claims are supported which means this PR might become outdated. There is also a similar PR: #48. See #73 for more details on the replacement of jwt-go.

@sergiught
Copy link
Contributor

We just released the v2.0.0-beta 🥳 !

You can start testing it by running go get github.com/auth0/go-jwt-middleware/[email protected].

In case of issues fetching the v2 you might want to try go clean --modcache first before doing go get.

I'm closing this pr as now this is part of v2, but feel free to reopen if needed.

@sergiught sergiught closed this Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants