-
Notifications
You must be signed in to change notification settings - Fork 22
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
WithCustomClaims in Verify token options should accept a type instead of pointer #202
Comments
Hello @vijathanga ! Sorry that you encountered this issue and thanks for reporting. Your observation is correct:
The Line 51 in 2f041fe
Do you perhaps mean a constructor function for new objects that will be populated with the custom claims? Something like: WithSessionV2(client, WithSessionClaimsFunc(func() interface{} {
return &MyCustomClaims{}
})
Would exposing the custom claims as a field in the clerk-sdk-go/clerk/middleware_v2.go Line 38 in 2f041fe
So to sum up the approach assuming a custom struct client, err := clerk.NewClient(apiKey)
// Configure the middleware
clerk.WithSessionV2(client, WithSessionClaimsFunc(func() interface{} {
return &MyCustomClaims{}
})
// In the request
sessionClaims, ok := clerk.SessionFromContext(req.Context())
if !ok {
// unauthenticated
}
customClaims, ok := sessionClaims.Custom.(*MyCustomClaims)
if ok {
// use customClaims
} Mostly asking if the final snippet would address your use case, this change will require some additional design considerations from our side! |
Hi @georgepsarakis, I appreciate the quick response. The final snippet looks good, It should satisfy our needs. Kindly keep me updated on the changes. Thanks! |
Thanks for the quick follow-up @vijathanga , I've opened a ticket internally so that we can look into this. |
@vijathanga Hello, sorry this took so long. We were preparing a new version for the Go SDK. Here's an attempt to solve the concurrent access issue by providing a constructor for the custom claims. Feel free to provide feedback and follow along with the discussion. |
Closing this since it is fixed in v2. |
Currently
WithCustomClaims
function intoken_option.go
accepts a pointer to a struct variable. So we have to define and pass the struct pointer when initializing theWithSessionV2
middleware. The same struct pointer is used for unmarshalling the custom claims for all incoming requests. This can cause consistency issues when multiple requests are processed at the same time.This can be solved by either
WithCustomClaims
function and dynamically create, populate the struct and set the value in contextThe text was updated successfully, but these errors were encountered: