fix: UniqueName aktualisiert, um den Benutzernamen in den Ansprüchen des Benutzernamens zu halten.
This commit is contained in:
parent
64717fbba5
commit
33ead6ebf4
@ -32,7 +32,7 @@ builder.Services.AddJwtSignatureHandler<Consumer>(api => new Dictionary<string,
|
|||||||
builder.Services.AddJwtSignatureHandler<UserReadDto>(user => new Dictionary<string, object>
|
builder.Services.AddJwtSignatureHandler<UserReadDto>(user => new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
{ JwtRegisteredClaimNames.Sub, user.Id },
|
{ JwtRegisteredClaimNames.Sub, user.Id },
|
||||||
{ JwtRegisteredClaimNames.UniqueName, user.Id },
|
{ JwtRegisteredClaimNames.UniqueName, user.Username },
|
||||||
{ JwtRegisteredClaimNames.Email, user.Email ?? string.Empty },
|
{ JwtRegisteredClaimNames.Email, user.Email ?? string.Empty },
|
||||||
{ JwtRegisteredClaimNames.GivenName, user.Prename ?? string.Empty },
|
{ JwtRegisteredClaimNames.GivenName, user.Prename ?? string.Empty },
|
||||||
{ JwtRegisteredClaimNames.FamilyName, user.Name ?? string.Empty },
|
{ JwtRegisteredClaimNames.FamilyName, user.Name ?? string.Empty },
|
||||||
@ -108,7 +108,37 @@ builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|||||||
&& token is not null)
|
&& token is not null)
|
||||||
context.Token = token;
|
context.Token = token;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
},
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.RequireHttpsMetadata = apiParams!.RequireHttpsMetadata;
|
||||||
|
options.ClaimsIssuer = apiParams!.Issuer;
|
||||||
|
options.Audience = apiParams.LocalConsumer.Audience;
|
||||||
|
options.TokenValidationParameters = new()
|
||||||
|
{
|
||||||
|
ValidateIssuer = true,
|
||||||
|
ValidIssuer = apiParams!.Issuer,
|
||||||
|
ValidateAudience = true,
|
||||||
|
ValidAudience = apiParams.LocalConsumer.Audience,
|
||||||
|
ValidateLifetime = true,
|
||||||
|
IssuerSigningKey = issuerSigningKeyInitiator?.Value
|
||||||
|
};
|
||||||
|
|
||||||
|
options.Events = new JwtBearerEvents
|
||||||
|
{
|
||||||
|
OnMessageReceived = context =>
|
||||||
|
{
|
||||||
|
// if there is no token read related cookie
|
||||||
|
if (context.Token is null // if there is no token
|
||||||
|
&& context.Request.Cookies.TryGetValue(apiParams!.DefaultCookieName, out var token) // get token from cookies
|
||||||
|
&& token is not null)
|
||||||
|
context.Token = token;
|
||||||
|
return Task.CompletedTask;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user