Skip to content

Commit

Permalink
fix(authentication): disable inbound claims mapping to make JWT Beare…
Browse files Browse the repository at this point in the history
…r scheme parse user ID correctly
  • Loading branch information
undrcrxwn committed Oct 11, 2024
1 parent d16e18a commit 39f95eb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/CrowdParlay.Social.Api/AuthenticationConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace CrowdParlay.Social.Api;
public static class AuthenticationConstants
{
public const string CookieAuthenticationUserIdClaim = "user_id";
public const string BearerAuthenticationUserIdClaim = "sub";
public const string JwtBearerAuthenticationUserIdClaim = "sub";
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static class ClaimsPrincipalExtensions
{
var userIdClaim = principal.Claims.FirstOrDefault(claim => claim.Type
is AuthenticationConstants.CookieAuthenticationUserIdClaim
or AuthenticationConstants.BearerAuthenticationUserIdClaim);
or AuthenticationConstants.JwtBearerAuthenticationUserIdClaim);

return Guid.TryParse(userIdClaim?.Value, out var value) ? value : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public static IServiceCollection ConfigureAuthentication(this IServiceCollection

builder.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, options =>
{
options.MapInboundClaims = false;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters.ValidateAudience = false;
options.TokenValidationParameters.ValidateIssuer = false;
Expand Down

0 comments on commit 39f95eb

Please sign in to comment.