fix(identity): align JWT claim mapping and add UserId fallbacks#1222
Open
cesarcastrocuba wants to merge 1 commit intofullstackhero:developfrom
Open
fix(identity): align JWT claim mapping and add UserId fallbacks#1222cesarcastrocuba wants to merge 1 commit intofullstackhero:developfrom
cesarcastrocuba wants to merge 1 commit intofullstackhero:developfrom
Conversation
- Set MapInboundClaims = false in ConfigureJwtBearerOptions to prevent .NET from remapping standard JWT claims to long URIs- Updated ClaimsPrincipalExtensions.GetUserId to support 'uid' and 'sub' claims, ensuring compatibility with Blazor-issued tokens- Added unit tests in Generic.Tests to verify claim priority (uid > sub > nameid)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
[fix]: Correct currentUserId in Blazor and API contexts
Description
This PR resolves an issue where
ICurrentUser.GetUserId()returnedGuid.Emptywhen called from a Blazor client context. The root cause was a mismatch between JWT claim names and the default .NET claim mapping.Key Changes:
options.MapInboundClaims = false;in ConfigureJwtBearerOptions.cs. This prevents ASP.NET Core from remapping standard short JWT claims (likesub,uid) to long XML SOAP URIs, ensuring consistency between the raw JWT and the ClaimsPrincipal.ClaimsPrincipalExtensions.GetUserId()to look foruidandsubclaims before falling back to NameIdentifier. This ensures that existing tokens and Blazor-issued tokens both resolve the User ID correctly.Related Issues
currentUserIdin Blazor pages.Verification
Generic.Teststo verify that GetUserId() correctly prioritizesuid>sub> NameIdentifier.Type of Change