【问题标题】:External Authentication failure ASP Identity OWIN Middleware外部身份验证失败 ASP Identity OWIN 中间件
【发布时间】:2017-08-20 06:45:08
【问题描述】:

我在我的网站中通过 ASP 身份框架使用 Google 和 Facebook 身份验证,两个提供商的外部登录在某些时候工作正常,但有时却不能,我不明白问题出在哪里,但工作正常当我重新启动应用程序时。

System.NullReferenceException:对象引用未设置为对象的实例。 在 Microsoft.AspNet.Identity.Owin.SignInManager`2.d__1d.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 SweetNightsIn.Identity.SiteUserManager.d__14.MoveNext() --- 从先前抛出异常的位置结束堆栈跟踪 --- 在 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在 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 +"
        });

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

【问题讨论】:

    标签: authentication asp.net-identity owin


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-18
      • 1970-01-01
      • 2017-09-11
      • 1970-01-01
      • 2019-08-12
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      相关资源
      最近更新 更多