UDT-003: Registro de Usuarios (admin-only) + fix JWT claim mapping #4
@@ -72,10 +72,13 @@ public static class DependencyInjection
|
|||||||
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
.AddJwtBearer();
|
.AddJwtBearer();
|
||||||
|
|
||||||
// Post-configure JWT Bearer — wire RSA public key + validation params from resolved options
|
// Post-configure JWT Bearer — wire RSA public key + validation params from resolved options.
|
||||||
|
// MapInboundClaims=false: preserve JWT claim names as-is ("sub", "rol", etc.).
|
||||||
|
// Without this, the middleware maps "sub" → ClaimTypes.NameIdentifier and breaks User.FindFirst("sub").
|
||||||
services.AddOptions<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme)
|
services.AddOptions<JwtBearerOptions>(JwtBearerDefaults.AuthenticationScheme)
|
||||||
.PostConfigure<RsaSecurityKey, JwtOptions>((jwtBearerOpts, rsaKey, jwtOpts) =>
|
.PostConfigure<RsaSecurityKey, JwtOptions>((jwtBearerOpts, rsaKey, jwtOpts) =>
|
||||||
{
|
{
|
||||||
|
jwtBearerOpts.MapInboundClaims = false;
|
||||||
jwtBearerOpts.TokenValidationParameters = new TokenValidationParameters
|
jwtBearerOpts.TokenValidationParameters = new TokenValidationParameters
|
||||||
{
|
{
|
||||||
ValidateIssuerSigningKey = true,
|
ValidateIssuerSigningKey = true,
|
||||||
@@ -86,7 +89,8 @@ public static class DependencyInjection
|
|||||||
ValidAudience = jwtOpts.Audience,
|
ValidAudience = jwtOpts.Audience,
|
||||||
ValidateLifetime = true,
|
ValidateLifetime = true,
|
||||||
ClockSkew = TimeSpan.Zero,
|
ClockSkew = TimeSpan.Zero,
|
||||||
RoleClaimType = "rol"
|
RoleClaimType = "rol",
|
||||||
|
NameClaimType = "name"
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user