Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ember.js/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 身份提供程序ASP.NET Facebook身份验证不起作用_C#_Asp.net_Facebook_Authentication_Oauth 2.0 - Fatal编程技术网

C# 身份提供程序ASP.NET Facebook身份验证不起作用

C# 身份提供程序ASP.NET Facebook身份验证不起作用,c#,asp.net,facebook,authentication,oauth-2.0,C#,Asp.net,Facebook,Authentication,Oauth 2.0,我正在使用Microsoft的Identity framework使用外部登录。除了Facebook,其他所有人都在工作。当我使用Facebook时,它允许我登录,但不要求许可,并立即返回登录页面,无需授权 回调url为 这是我的外部登录身份验证码(ID和密码为空): 它会将我重定向到的预期结果是:localhost/Account/externalloginsucseed我也遇到了类似的问题,尽管在更新以下nuget软件包时已解决: Microsoft.Owin到3.1.0版 Microsof

我正在使用Microsoft的Identity framework使用外部登录。除了Facebook,其他所有人都在工作。当我使用Facebook时,它允许我登录,但不要求许可,并立即返回登录页面,无需授权

回调url为

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


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

我也遇到了类似的问题,尽管在更新以下nuget软件包时已解决:

  • Microsoft.Owin到3.1.0版
  • Microsoft.Owin.Security至3.1.0版
  • Microsoft.Owin.Security.Cookies至3.1.0版
  • Microsoft.Owin.Security.OAuth至3.1.0版
  • 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,我也遇到了类似的问题,不过在更新以下nuget软件包时得到了解决:

  • Microsoft.Owin到3.1.0版
  • Microsoft.Owin.Security至3.1.0版
  • Microsoft.Owin.Security.Cookies至3.1.0版
  • Microsoft.Owin.Security.OAuth至3.1.0版
  • 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,首先是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);
    

    首先,您必须拥有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);
    

    修正了我的问题-谢谢!在进一步研究这个问题之后,以下是它停止工作的原因:修复了我的问题-谢谢!在进一步研究该问题后,以下是它停止工作的原因: