Browse Source

More schema

davidfowl/common-services
David Fowler 1 year ago
committed by Reuben Bond
parent
commit
8a40e9fb48
3 changed files with 24 additions and 9 deletions
  1. +0
    -6
      src/Services/Basket/Basket.API/Program.cs
  2. +5
    -0
      src/Services/Basket/Basket.API/appsettings.json
  3. +19
    -3
      src/Services/Services.Common/CommonExtensions.cs

+ 0
- 6
src/Services/Basket/Basket.API/Program.cs View File

@ -15,12 +15,6 @@ builder.Services.AddControllers(options =>
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.AddTransient<ProductPriceChangedIntegrationEventHandler>();


+ 5
- 0
src/Services/Basket/Basket.API/appsettings.json View File

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


+ 19
- 3
src/Services/Services.Common/CommonExtensions.cs View File

@ -150,13 +150,29 @@ public static class CommonExtensions
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.
JwtSecurityTokenHandler.DefaultInboundClaimTypeMap.Remove("sub");
services.AddAuthentication().AddJwtBearer(options =>
{
var identityUrl = configuration.GetRequiredValue("IdentityUrl");
var audience = configuration.GetRequiredValue("Audience");
var identityUrl = identitySection.GetRequiredValue("Url");
var audience = identitySection.GetRequiredValue("Audience");
options.Authority = identityUrl;
options.RequireHttpsMetadata = false;
@ -166,7 +182,7 @@ public static class CommonExtensions
services.AddAuthorization(options =>
{
var scope = configuration.GetRequiredValue("Scope");
var scope = identitySection.GetRequiredValue("Scope");
options.AddPolicy("ApiScope", policy =>
{


Loading…
Cancel
Save