-
Notifications
You must be signed in to change notification settings - Fork 20
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
feat: JWT parsing with custom claims #253
Conversation
b11bc36
to
be62a04
Compare
http/middleware.go
Outdated
// // custom claims are available in the SessionClaims.Custom field. | ||
// sessionClaims, ok := clerk.SessionClaimsFromContext(r.Context()) | ||
// customClaims, ok := sessionClaims.Custom.(*MyCustomClaims) | ||
func CustomClaimsConstructor(constructor func() any) AuthorizationOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❓ Would it make sense to pass the request context in the constructor?
func CustomClaimsConstructor(constructor func() any) AuthorizationOption { | |
func CustomClaimsConstructor(constructor func(ctx context.Context) any) AuthorizationOption { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but since this goes down to jwt.Verify
, the context might not make sense there.
We can have different params for middleware and jwt.Verify
though. I'll revise this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was wrong, jwt.Verify does accept a context. 😄
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly noted this because it's going to be tough to change afterwards.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And you were 100% right to do so 🙏 😄
Replaced the CustomClaims parameter with a CustomClaimsConstructor function when verifying a session JWT. The option is also available in the HTTP middleware. The constructor function will be called when the JWT is parsed, producing a new struct instance instead of writing on a single instance. The custom claims will be made available in the SessionClaims.Custom field.
be62a04
to
c803c14
Compare
Replaced the CustomClaims parameter with a CustomClaimsConstructor function when verifying a session JWT. The option is also available in the HTTP middleware.
The constructor function will be called when the JWT is parsed, producing a new struct instance instead of writing on a single instance.
The custom claims will be made available in the SessionClaims.Custom field.