More schema

This commit is contained in:
David Fowler 2023-05-02 11:11:13 -07:00 committed by Reuben Bond
parent 3fee612e68
commit 8a40e9fb48
3 changed files with 24 additions and 9 deletions

View File

@ -15,12 +15,6 @@ builder.Services.AddControllers(options =>
options.Filters.Add(typeof(ValidateModelStateFilter)); options.Filters.Add(typeof(ValidateModelStateFilter));
}); });
builder.WebHost.UseFailing(options =>
{
options.ConfigPath = "/Failing";
options.NotFilteredPaths.AddRange(new[] { "/hc", "/liveness" });
});
builder.Services.AddRedis(builder.Configuration); builder.Services.AddRedis(builder.Configuration);
builder.Services.AddTransient<ProductPriceChangedIntegrationEventHandler>(); builder.Services.AddTransient<ProductPriceChangedIntegrationEventHandler>();

View File

@ -19,6 +19,11 @@
"ConnectionStrings": { "ConnectionStrings": {
"Redis": "127.0.0.1" "Redis": "127.0.0.1"
}, },
"Identity": {
"Url": "",
"Auidence": "basket",
"Scope": "basket"
},
"EventBus": { "EventBus": {
"SubscriptionClientName": "Basket", "SubscriptionClientName": "Basket",
"ConnectionString": "your-event-bus-connection-string", "ConnectionString": "your-event-bus-connection-string",

View File

@ -150,13 +150,29 @@ public static class CommonExtensions
public static IServiceCollection AddDefaultAuthentication(this IServiceCollection services, IConfiguration configuration) public static IServiceCollection AddDefaultAuthentication(this IServiceCollection services, IConfiguration configuration)
{ {
// {
// "Identity": {
// "Url": "http://identity",
// "Audience": "basket",
// "Scope": "basket"
// }
// }
var identitySection = configuration.GetSection("Identity");
if (identitySection is null)
{
// No identity section, so no authentication
return services;
}
// prevent from mapping "sub" claim to nameidentifier. // prevent from mapping "sub" claim to nameidentifier.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub"); JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
services.AddAuthentication().AddJwtBearer(options => services.AddAuthentication().AddJwtBearer(options =>
{ {
var identityUrl = configuration.GetRequiredValue("IdentityUrl"); var identityUrl = identitySection.GetRequiredValue("Url");
var audience = configuration.GetRequiredValue("Audience"); var audience = identitySection.GetRequiredValue("Audience");
options.Authority = identityUrl; options.Authority = identityUrl;
options.RequireHttpsMetadata = false; options.RequireHttpsMetadata = false;
@ -166,7 +182,7 @@ public static class CommonExtensions
services.AddAuthorization(options => services.AddAuthorization(options =>
{ {
var scope = configuration.GetRequiredValue("Scope"); var scope = identitySection.GetRequiredValue("Scope");
options.AddPolicy("ApiScope", policy => options.AddPolicy("ApiScope", policy =>
{ {