问题描述
我对正在使用的.netcore3.1应用程序上发生的错误感到沮丧。 这是我的设置:
在Startup.cs
services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
.AddMicrosoftWebApp(options =>
{
Configuration.Bind("AzureAd",options);
options.Events ??= new OpenIdConnectEvents();
options.Events.OnRedirectToIdentityProvider = async ctx =>
{
ctx.ProtocolMessage.RedirectUri = Configuration["AzureAd:RedirectUri"];
await Task.CompletedTask;
};
})
.AddMicrosoftWebAppCallsWebApi(Configuration,new[] { "user.read" })
.AdddistributedTokenCaches();
在我的应用程序设置中
"AzureAd": {
"Instance": "https://login.microsoftonline.com/","ClientId": "ClientId","TenantId": "TenantId","RedirectUri": "https://mywebsite.com/signin-oidc","ClientSecret": "ClientSecret"
},
使用https://mywebsite.com/signin-oidc作为重定向URL正确配置了Azure应用注册。 我还添加了以下内容,以允许从代理转发标头:
services.Configure<ForwardedHeadersOptions>(options =>
{
options.ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto;
options.KNownNetworks.Clear();
options.KNownProxies.Clear();
});
// then in the Configure method
app.UseForwardedHeaders();
ctx.ProtocolMessage.RedirectUri = Configuration["AzureAd:RedirectUri"];
我会克服这个问题,但似乎对这个错误没有影响。
An unhandled exception occurred","Properties":{"CorrelationId":"c3393560-6ebe-41ce-99fc-693c1a387474","Path":"/signin-oidc","Method":"POST","exceptionMessage":"An error was encountered while handling the remote login.","exception":"System.Exception: An error was encountered while handling the remote login.\n ---> MSAL.NetCore.4.16.1.0.MsalServiceException: \n\tErrorCode: invalid_client\nMicrosoft.Identity.Client.MsalServiceException: A configuration issue is preventing authentication - check the error message from the server for details.You can modify the configuration in the application registration portal. See https://aka.ms/msal-net-invalid-client for details. Original exception: AADSTS500112: The reply address 'http://mywebsite.com/signin-oidc' does not match the reply address 'https://mywebsite.com/signin-oidc' provided when requesting Authorization