Es gibt eine Blazor-Server-App, die die Haupt-Web-API aufrufen muss, um Daten abzurufen und Aktionen usw. auszuführen. Ich habe dies mithilfe eines OIDC-Flows mit aktivierter Client-Authentifizierung und Standard-Flow gesichert. Die Web-API wird mit JWTBearer gesichert.
Beide Dienste können sich unabhängig voneinander authentifizieren und arbeiten, aber ich bin mir nicht sicher, wie ich die beiden dazu bringen kann, miteinander zu kommunizieren. Ich dachte, ich würde eine Art Token-Austausch durchführen, aber ich scheine kein Token zum Austauschen zu haben (zumindest nicht in meinem http-Kontext, ich scheine nicht einmal einen Authentifizierungs-Header zu haben).
Die Authentifizierungskonfiguration für die API ist in der Programmdatei wie folgt:
Code: Select all
builder.Services.AddAuthentication()
.AddJwtBearer(o =>
{
o.RequireHttpsMetadata = false;
o.Audience = builder.Configuration["Authentication:Audience"];
o.MetadataAddress = builder.Configuration["Authentication:MetadataAddress"]!;
o.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = builder.Configuration["Authentication:ValidIssuer"]
};
});
Code: Select all
builder.Services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = "oidc";
})
.AddCookie()
.AddOpenIdConnect("oidc", options =>
{
var oidcConfig = builder.Configuration.GetSection("OpenIDConnectSettings");
options.Authority = oidcConfig["Authority"];
options.ClientId = oidcConfig["ClientId"];
options.ClientSecret = oidcConfig["ClientSecret"];
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.ResponseType = OpenIdConnectResponseType.Code;
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true;
options.MapInboundClaims = false;
options.RequireHttpsMetadata = false;
options.TokenValidationParameters.NameClaimType = JwtRegisteredClaimNames.Name;
options.TokenValidationParameters.RoleClaimType = "roles";
});
Mobile version