Allow overriding username claim name#11
Allow overriding username claim name#11singhman13 wants to merge 1 commit intoStephanDollberg:masterfrom
Conversation
The username claim name identifies the JWT payload claim which contains the username. For example, some external providers use the "sub" (Subject) IANA registered claim name. (See RFC 7519.)
|
Hi @khalsa72 , thanks for the detailed PR and all the explanations. I think that it makes sense to fully move from As such, I will wait with this for I will leave this open till then. Thanks, |
|
Stephan, There is a common use case for overriding username claim which will benefit from merging this before v3. While the Depending on your application requirements you might choose to use the Alternatively, you might decide that you want to link to the I think it's worth merging the current PR as-is and then switching to "sub" as the default in with Disclaimer: My opinion is biased as I would like to stop using my fork and switch back to your repo. Thanks, -Manpreet |
|
Hi Manpreet, I get your point, on the other side I am still resistent of adding too many features and would like to wait for jwt-go to get a feeling of how it would look in the end. I will think about it. Cheers, |
|
Hi @khalsa72, I have thought about it and just don't feel like it makes sense to push this into now. Like I said I want to keep the middleware pretty simple and first want to wait for v3 to see how it would look. Thanks, |
|
Understood, I can wait till v3. |
Added an additional configuration parameter to allow overriding the username claim name identifying the JWT payload claim which contains the username. For example, some external providers (Google, Auth0) use the "sub" (Subject) IANA registered claim name. (See RFC 7519.)
Use case: required when the tokens are generated by an external entity (e.g. Auth0 for user management) and need the middleware for verification only.
Was considering if it's worth using "sub" by default instead of "id", so that the default out of the box configuration works for both locally and externally generated tokens (at least those using RFC 7519 recommendations.) Would probably need fallback to "id" if a "sub" claim isn't present to allowing any existing issued tokens to still work. Not sure if it's worth the effort. Also might be a breaking change for some, depending on if
request.Env["JWT_PAYLOAD"]"id" claim is being accessed directly, although they should be usingrequest.Env["REMOTE_USER"]instead.Relevant extracts from RFC 7519 in case anyone is interested.
https://tools.ietf.org/html/rfc7519
4.1. Registered Claim Names
4.1.2. "sub" (Subject) Claim