Map Keycloak name claim
This commit is contained in:
@@ -21,6 +21,7 @@ builder.Services.AddAuthentication()
|
|||||||
options.RequireHttpsMetadata = !builder.Environment.IsDevelopment();
|
options.RequireHttpsMetadata = !builder.Environment.IsDevelopment();
|
||||||
options.Audience = KeycloakConstants.ClientId;
|
options.Audience = KeycloakConstants.ClientId;
|
||||||
options.Authority = keycloakHost;
|
options.Authority = keycloakHost;
|
||||||
|
options.TokenValidationParameters.NameClaimType = "preferred_username";
|
||||||
});
|
});
|
||||||
builder.Services.AddAuthorization();
|
builder.Services.AddAuthorization();
|
||||||
|
|
||||||
@@ -55,6 +56,14 @@ app.MapGet("/weatherforecast", () =>
|
|||||||
.WithName("GetWeatherForecast")
|
.WithName("GetWeatherForecast")
|
||||||
.RequireAuthorization();
|
.RequireAuthorization();
|
||||||
|
|
||||||
|
app.MapGet("/test", (HttpContext context) =>
|
||||||
|
{
|
||||||
|
_ = context.User;
|
||||||
|
return TypedResults.Ok();
|
||||||
|
})
|
||||||
|
.WithName("Test Endpoint")
|
||||||
|
.RequireAuthorization();
|
||||||
|
|
||||||
app.MapDefaultEndpoints();
|
app.MapDefaultEndpoints();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
Reference in New Issue
Block a user