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

Support for dynamic public key from jwt token #286

Open
1 task done
prasadsawant12 opened this issue Sep 21, 2024 · 1 comment
Open
1 task done

Support for dynamic public key from jwt token #286

prasadsawant12 opened this issue Sep 21, 2024 · 1 comment
Labels
feature request A feature has been asked for or suggested by the community

Comments

@prasadsawant12
Copy link

prasadsawant12 commented Sep 21, 2024

Checklist

Describe the problem you'd like to have solved

I am upgrading my go-jwt-middleware pkg from v1 to v2. In older implementation there was option to generate public key from token. here is the sample code
func GetJwtMiddleware() *jwtmiddleware.JWTMiddleware { jwtMiddleware := jwtmiddleware.New(jwtmiddleware.Options{ ValidationKeyGetter : func(token *jwt.Token) (interface{}, error) { cert, err := getPemCert(token) if err != nil { panic(err.Error()) } result, _ := jwt.ParseRSAPublicKeyFromPEM([]byte(cert)) return result, nil } SigningMethod: jwt.SigningMethodRS256, }) return jwtMiddleware }

But in V2, there is no option generate public key from token as token is not available in keyFunc function.

Describe the ideal solution

JWT token should be available in keyFunc function along with ctx

Alternatives and current workarounds

No response

Additional context

No response

@prasadsawant12 prasadsawant12 added the feature request A feature has been asked for or suggested by the community label Sep 21, 2024
@developerkunal
Copy link
Contributor

Hi @prasadsawant12,

Hope you're doing well!

Thanks for reaching out. In v2, the keyFunc function no longer receives the token, likely for security reasons. Could you share more about your use case? Are you trying to extract the public key dynamically? Happy to help guide you toward a secure solution!

To align with the updated design and best security practices, it's recommended to manage public keys separately from tokens. Here’s how you can proceed:

🔹 Utilize a JWKS Endpoint – If your authentication provider offers a JWKS (JSON Web Key Set) endpoint, configure your application to fetch public keys from there. This ensures centralized and secure key management.

Would love to hear your thoughts on this approach! Let me know how I can help. 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature has been asked for or suggested by the community
Projects
None yet
Development

No branches or pull requests

2 participants