Asp.net 核心和 Microsoft 帐户身份验证访问被拒绝

Asp.net Core and Microsoft account authentication access denied

我正在尝试在 ASP.net 核心应用程序中设置 Microsoft 帐户身份验证。
我几乎已经关注 ben day's post 希望我无法走到尽头。
一旦用户被重定向到应该输入电子邮件地址的步骤,我就会被重定向到拒绝访问的页面(来自我的 asp.net 应用程序)。
在控制台中,我可以看到以下错误消息:

Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware:Information: AuthenticationScheme: Identity.External signed in. Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request finished in 1260.8977ms 302 Microsoft.AspNetCore.Hosting.Internal.WebHost:Information: Request starting HTTP/1.1 GET http://localhost:44394/
Microsoft.AspNetCore.Authorization.DefaultAuthorizationService:Information: Authorization failed for user: . Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker:Warning: Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.Authorization.AuthorizeFilter'. Microsoft.AspNetCore.Mvc.ChallengeResult:Information: Executing ChallengeResult with authentication schemes (). Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware:Information: AuthenticationScheme: Identity.External was successfully authenticated. Microsoft.AspNetCore.Authentication.Cookies.CookieAuthenticationMiddleware:Information: AuthenticationScheme: Identity.External was forbidden. Microsoft.AspNetCore.Authentication.MicrosoftAccount.MicrosoftAccountMiddleware:Information: AuthenticationScheme: Microsoft was forbidden.

这是我目前的配置(非常简单)

app.UseIdentity(); app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions { DisplayName = "Microsoft Account", ClientId = "my id", ClientSecret = "my secret", AutomaticChallenge = true });

知道为什么我的访问被拒绝了吗?

我正在尝试构建一个 Asp.Net 核心 Web 应用程序,它使用 Microsoft 帐户进行身份验证并且对我来说效果很好。它使用 cookie 和 Microsoft 帐户组件,这里是供您参考的代码:

app.UseCookieAuthentication(new CookieAuthenticationOptions());

app.UseMicrosoftAccountAuthentication(new MicrosoftAccountOptions {
            DisplayName = "Microsoft Account",
            ClientId = "",
            ClientSecret = "",
            AutomaticChallenge = true,
            SignInScheme= "Cookies"
});

public async Task Login()
{

     await HttpContext.Authentication.ChallengeAsync(new AuthenticationProperties() { RedirectUri = "/" });
}

您可以参考 here. To run this code sample, you need to register the apps from here first and add the web platform and config the redirect URL http://localhost:7507/signin-microsoft 中的完整代码示例。

而对于原问题,由于已经没有Asp.net 5个模板,如果您能提供一个演示项目来帮助重现这个问题,那将很有帮助。