【问题标题】:Identity provider ASP.NET Facebook Authentication not working身份提供程序 ASP.NET Facebook 身份验证不起作用
【发布时间】:2017-07-04 07:04:14
【问题描述】:

我正在使用 Microsoft 的身份框架来使用外部登录。除了 Facebook,其他人都在工作。当我使用 Facebook 时,它让我登录但不请求许可,并立即将我返回到登录页面,而未经授权。

回调地址为http://localhost:14613/signin-facebook/

这是我的外部登录验证码(ID 和秘密为空白):

app.UseFacebookAuthentication(
               appId: "XXXXXXX",
               appSecret: "XXXXXXX"
            );

它会将我重定向到的预期结果:localhost/Account/ExternalLoginSucceeded

【问题讨论】:

    标签: c# asp.net facebook authentication oauth-2.0


    【解决方案1】:

    我也遇到了类似的问题,但在更新以下 nuget 包时得到了解决:

    1. Microsoft.Owin 到版本 3.1.0
    2. Microsoft.Owin.Security 到版本 3.1.0
    3. Microsoft.Owin.Security.Cookies 到版本 3.1.0
    4. Microsoft.Owin.Security.OAuth 到版本 3.1.0
    5. Microsoft.Owin.Security.Facebook 到版本 3.1.0

    Startup.cs 代码为:

    var facebookOptions = new FacebookAuthenticationOptions()
    {
         AppId = "xxxxxx",
         AppSecret = "xxxxxx", 
         Scope = { "email" },
         Provider = new FacebookAuthenticationProvider()
          {
             OnAuthenticated = (context) =>
               {
                   context.Identity.AddClaim(new Claim("urn:facebook:accesstoken", context.AccessToken, ClaimValueTypes.String, "Facebook"));
                   return Task.FromResult(0);
               }
          }
    }; 
    app.UseFacebookAuthentication(facebookOptions);
    

    而我的 facebook graph api 版本是 2.8

    【讨论】:

    【解决方案2】:

    首先你有Owin版本

    3.1.0

    随 NuGet 安装

    我找到了某种类似的解决方案,我对其进行了更改并更新了它以获得其他功能,例如让 facebook 用户喜欢并且效果很好

    这是代码(粘贴在 Startup.Auth 中):

            var facebookOptions = new FacebookAuthenticationOptions()
            {
                AppId =     "-----copy from your facebook app-----",
                AppSecret = "-----copy from your facebook app-----",
                Provider = new FacebookAuthenticationProvider
                {
                    OnAuthenticated = context =>
                    {
                        context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
                        return Task.FromResult(true);
                    }
                },
    
                //BackchannelHttpHandler = new FacebookBackChannelHandler(),
                //UserInformationEndpoint = "https://graph.facebook.com/v2.4/me?fields=id,name,email,first_name,last_name,location"
            };
            facebookOptions.Scope.Add("email");
            //facebookOptions.Scope.Add("user_likes");
            app.UseFacebookAuthentication(facebookOptions);
    

    【讨论】:

      猜你喜欢
      • 2011-05-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-25
      • 2020-09-28
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 2015-08-24
      相关资源
      最近更新 更多