这通常是由于应用程序的回复URL未正确配置导致的。要解决此问题,请确保将正确的回复URL配置在应用程序中。以下是在ASP.NET Core中配置回复URL的示例代码:
services
.AddAuthentication()
.AddMicrosoftAccount(options =>
{
options.ClientId = Configuration["Authentication:Microsoft:ClientId"];
options.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
options.CallbackPath = "/signin-microsoft";
options.AuthorizationEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/authorize";
options.TokenEndpoint = "https://login.microsoftonline.com/common/oauth2/v2.0/token";
options.UserInformationEndpoint = "https://graph.microsoft.com/v1.0/me";
options.SaveTokens = true;
options.Events = new MicrosoftAccountEvents
{
OnRemoteFailure = (context) =>
{
context.HandleResponse();
context.Response.Redirect("/home/error?ErrorMessage=" + context.Failure.Message);
return Task.FromResult(0);
}
};
options.Scope.Add("https://graph.microsoft.com/user.read");
options.Scope.Add("https://graph.microsoft.com/mailboxsettings.read");
});
该示例代码中的'CallbackPath”属性指定了回复URL,您应该将其设置为与应用程序中配置的回复URL相匹配的URL。如果您在使用其他身份验证提供程序,请确保同样正确配置其回复URL。