外部身份验证失败 ASP 身份 OWIN 中间件

External Authentication failure ASP Identity OWIN Middleware

我在我的站点中通过 ASP 身份框架使用 Google 和 Facebook 身份验证,两个提供商的外部登录在某些时候都可以正常工作,但有时却不行,我做不到了解问题出在哪里,但当我重新启动应用程序时它工作正常。

System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.AspNet.Identity.Owin.SignInManager`2.d__1d.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SweetNightsIn.Identity.SiteUserManager.d__14.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at SweetNightsIn.Web.Controllers.AccountController.d__3.MoveNext()

OWIN startup.cs 看起来像这样,

// For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=316888
        app.CreatePerOwinContext(IdentityDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);

        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString(AppConstants.LoginPath)

        });

        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        FacebookAuthenticationOptions facebookOptions = new FacebookAuthenticationOptions()
        {
            AppId = ConfigurationManager.AppSettings["FacebookAppId"],
            AppSecret = ConfigurationManager.AppSettings["FacebookAppSecret"],
            UserInformationEndpoint = "https://graph.facebook.com/v2.8/me?fields=id,name,email",
            BackchannelHttpHandler = new FacebookBackChannelHandler()
        };

        facebookOptions.Scope.Add("email");

        app.UseFacebookAuthentication(facebookOptions);

        app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
        {
            ClientId = ConfigurationManager.AppSettings["GoogleAppId"],
            ClientSecret = ConfigurationManager.AppSettings["GoogleAppSecret"],
            Caption = "Google +"
        });

如果您需要更多信息,请回复

此特定错误是由于 Facebook API 更改造成的,主要更改涉及从 API 升级到 JSON 格式

的响应