【问题标题】:facebook oAuth External Authentication redirect url doesnot work in MVCfacebook oAuth 外部身份验证重定向 URL 在 MVC 中不起作用
【发布时间】:2017-04-13 18:47:16
【问题描述】:

我创建了一个启用了 Individaul Auth 的 MVC SPA 应用程序。并将所有 OWIN DLL 更新到 3.1.0 版本。更新了startup.cs中注册的AppID和Key(来自DeConsole)

在登录页面中启用了“Facebook”按钮,单击它会将我带到 FB 登录页面以提供我的凭据。登录后,它不会执行任何确认,例如谷歌询问(应用程序尝试访问您的基本信息允许/拒绝),然后重定向回应用程序。但是没有从FB得到任何基本信息。我在这里有什么遗漏吗 返回网址始终为 localhost:33343/Account/Login#=_..

我以为微软 正在提供我们需要的一切,但实际上并非如此。

【问题讨论】:

    标签: asp.net-mvc authentication oauth-2.0


    【解决方案1】:

    您一定是从 OWIN 中间件获得了 access_denied。尝试将调试器放在 Account Controller 操作“ExternalLoginCallback”中。

    我假设您已在 facebook 中添加 http://your_domain/signin-facebook 作为允许的 redirect_uri。注意,这里 https 不是强制性的,如果是 http,facebook 仍然提供凭据。

    我还假设您已将 nuget 包更新到 Microsoft.Owin.Security.Facebook 3.1.0。 有用链接:https://github.com/aspnet/AspNetKatana/issues/38

    请参阅:https://developers.facebook.com/docs/facebook-login/permissions 以查看允许的权限。要求正确的范围和字段如下代码:

    var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
            {
                AppId = "....",
                AppSecret = "....",
    
                AuthenticationType = "Facebook",
                SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie,                
    
                Provider = new FacebookAuthenticationProvider
                {
                    OnAuthenticated = async ctx =>
                    {
                        ctx.Identity.AddClaim(new Claim("FacebookAccessToken", ctx.AccessToken));
                        foreach (var claim in ctx.User)
                        {
                            var claimType = string.Format("urn:facebook:{0}", claim.Key);
                            string claimValue = claim.Value.ToString();
    
                            if (!ctx.Identity.HasClaim(claimType, claimValue))
                            {
                                ctx.Identity.AddClaim(new Claim(claimType, claimValue, "XmlSchemaString", "Facebook"));
                            }
                        }                 
                    }
    
                }
            };
    
            // Set requested scope
            facebookAuthenticationOptions.Scope.Add("email");
            facebookAuthenticationOptions.Scope.Add("public_profile");
    
            // Set requested fields
            facebookAuthenticationOptions.Fields.Add("email");
            facebookAuthenticationOptions.Fields.Add("first_name");
            facebookAuthenticationOptions.Fields.Add("last_name");                 
    
            app.UseFacebookAuthentication(facebookAuthenticationOptions);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-04
      • 2012-12-18
      • 1970-01-01
      • 2011-09-17
      • 1970-01-01
      • 2012-04-14
      • 2015-06-26
      相关资源
      最近更新 更多