PatriQ
PatriQ
CC#
Created by PatriQ on 6/12/2023 in #help
❔ SignalR .NET 7 API Dependency injection not working
Hello. As I have described here https://github.com/dotnet/aspnetcore/issues/46095#issuecomment-1587264717 with a trivial example, I cannot manage to make Dependency injection work with SignalR. Been trying so for days. Any help would be appreciated.
14 replies
CC#
Created by PatriQ on 2/22/2023 in #help
❔ AddAuthentication configured dynamically per request within middleware
Hey. I've got a list of tenants in appsettings.json, which can be updated at runtime. I was wondering, if its possible to somehow move this code to a custom middleware, so configuration of authentication can be dynamically updated at runtime.
var tenants = builder.Configuration.GetSection("Tenants").Get<List<Tenant>>();
foreach (var tenant in tenants)
{
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, o =>
{
o.MetadataAddress = tenant.MetadataAddress;
o.RequireHttpsMetadata = tenant.HTTPS;
o.Authority = tenant.Authority;
o.Audience = "account";
o.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = tenant.Issuer,
ValidateLifetime = true,
ClockSkew = TimeSpan.FromMinutes(0)
};
});
}
var tenants = builder.Configuration.GetSection("Tenants").Get<List<Tenant>>();
foreach (var tenant in tenants)
{
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, o =>
{
o.MetadataAddress = tenant.MetadataAddress;
o.RequireHttpsMetadata = tenant.HTTPS;
o.Authority = tenant.Authority;
o.Audience = "account";
o.TokenValidationParameters = new TokenValidationParameters
{
ValidateIssuer = true,
ValidIssuer = tenant.Issuer,
ValidateLifetime = true,
ClockSkew = TimeSpan.FromMinutes(0)
};
});
}
2 replies