相关疑难解决方法(0)

为什么新的fb api 2.4在带有Identity和oauth 2的MVC 5上返回null电子邮件?

一切都习以为常,直到fb将api升级到2.4 (我以前的项目中有2.3).

今天当我在fb开发人员上添加一个新的应用程序时,我得到了api 2.4.

问题:现在我从fb(loginInfo.email = null)收到空电子邮件.

当然,我检查了用户电子邮件在fb配置文件中处于公共状态,

我去了loginInfo对象,但没有找到任何其他电子邮件地址.

我谷歌,但没有找到任何答案.

请任何帮助..我有点迷路..

谢谢,

我的原始代码(适用于2.3 api):

在AccountController.cs中:

//
// GET: /Account/ExternalLoginCallback
[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
    var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
    if (loginInfo == null)
    {
        return RedirectToAction("Login");
    }
    //A way to get fb details about the log-in user: 
    //var firstNameClaim = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:first_name");  <--worked only on 2.3
    //var firstNameClaim = loginInfo.ExternalIdentity.Claims.First(c => c.Type == "urn:facebook:name"); <--works on 2.4 api …
Run Code Online (Sandbox Code Playgroud)

c# facebook facebook-graph-api asp.net-mvc-5 asp.net-identity-2

46
推荐指数
5
解决办法
1万
查看次数

如何使用ASP.NET身份(OWIN)访问Facebook私人信息?

我正在ASP.NET MVC 5中开发一个网站(目前使用RC1版本).该网站将使用Facebook进行用户身份验证和检索初始个人资料数据.

对于身份验证系统,我使用的是基于OWIN的新ASP.NET身份引擎(http://blogs.msdn.com/b/webdev/archive/2013/07/03/understanding-owin-forms-authentication-in-mvc -5.aspx),因为它极大地简化了与外部提供商进行身份验证的过程.

问题是,一旦用户首次登录,我想从Facebook个人资料中获取其电子邮件地址,但此数据不包含在生成的声明中.所以我考虑过这些替代方案来获取地址:

  1. 指示ASP.NET标识引擎将电子邮件地址包含在从Facebook检索的数据集中,然后转换为声明.我不知道这是否可行.

  2. 使用Facebook图形API(https://developers.facebook.com/docs/getting-started/graphapi)通过使用Facebook用户ID(包含在声明数据中)来检索电子邮件地址.但是,如果用户将其电子邮件地址设置为私有,则此操作无效.

  3. 使用Facebook图形API,但指定"我"而不是Facebook用户ID(https://developers.facebook.com/docs/reference/api/user).但是需要一个访问令牌,我不知道如何(或者根本不可能)检索ASP.NET用来获取用户数据的访问令牌.

所以问题是:

  1. 如何指示ASP.NET标识引擎从Facebook检索其他信息并将其包含在声明数据中?

  2. 或者,我如何检索生成的访问令牌,以便我自己可以询问Facebook?

谢谢!

注意:对于身份验证系统,我的应用程序使用基于此SO答案中链接的示例项目的代码:https://stackoverflow.com/a/18423474/4574

asp.net-mvc facebook-graph-api owin asp.net-mvc-5 asp.net-identity

31
推荐指数
4
解决办法
3万
查看次数

如何使用ASP.NET MVC 5和OWIN获取Facebook的名字和姓氏值?

我知道提供了"名称"字段,但我更愿意明确地访问名字和姓氏.有人可以帮忙吗?我仍然围绕着ASP.Net MVC.

asp.net-mvc facebook owin asp.net-mvc-5

20
推荐指数
4
解决办法
2万
查看次数

如何使用刷新令牌续订访问令牌?

我正在使用带有OWIN的ASP.NET MVC 5.

我做了很多研究,但没有找到如何使用刷新令牌续订访问令牌.

我的方案是:用户第一次访问我的应用时,他或她授予访问我读取API返回的刷新令牌的帐户的权限.当用户返回我的应用程序时,我需要根据"刷新令牌"刷新访问令牌.

有人可以提供一些代码吗?

这是我到目前为止所取得的成就:

Startup.Auth.cs:

    var googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions
    {
        Caption = "Google+",
        ClientId = Parameters.Instance.Authentication.oAuth.GooglePlus.ClientId,
        ClientSecret = Parameters.Instance.Authentication.oAuth.GooglePlus.ClientSecret,
        CallbackPath = new PathString("/oauth-login-return"),
        Provider = new GoogleOAuth2AuthenticationProvider
        {
            OnAuthenticated = async context =>
            {
                context.Identity.AddClaim(new Claim(ClaimTypes.Name, context.Identity.FindFirstValue(ClaimTypes.Name)));
                context.Identity.AddClaim(new Claim(ClaimTypes.Email, context.Identity.FindFirstValue(ClaimTypes.Email)));
                context.Identity.AddClaim(new Claim("picture", context.User.GetValue("picture").ToString()));
                context.Identity.AddClaim(new Claim("profile", context.User.GetValue("profile").ToString()));
                context.Identity.AddClaim(
                    new Claim(Parameters.Instance.Authentication.oAuth.GooglePlus.AccessTokenClaimType,
                        context.AccessToken));
            }
        }
    };
    googleOAuth2AuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/plus.login");
    googleOAuth2AuthenticationOptions.Scope.Add("https://www.googleapis.com/auth/userinfo.email");
Run Code Online (Sandbox Code Playgroud)

AuthenticationController:

[HttpPost]
[AllowAnonymous]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
    RedirectIfAuthenticated();

    return new ChallengeResult(provider, Url.Content("~/oauth-login-callback"));
}

[ActionName("oauth-login-back")]
public …
Run Code Online (Sandbox Code Playgroud)

c# oauth-2.0 google-oauth owin asp.net-mvc-5

15
推荐指数
1
解决办法
2万
查看次数

MVC5上的Google OAuth ExternalLoginCallback?error = access_denied

我已经设置了Google OAuth

在此输入图像描述

我已将代码添加到Startup.Auth.cs中

 app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions()
    {
        // LRC
        ClientId = "xxxxxxxxx",
        ClientSecret = "xxxxx"
        //CallbackPath = new PathString("/signin-google")
    });
Run Code Online (Sandbox Code Playgroud)

但在我选择Google帐户登录后,它又将我重定向到了登录页面,

我通过Chrome检查了网络,发现访问被拒绝了.

http://www.liferunningclub.com.au/Account/ExternalLoginCallback?error=access_denied

我想不明白.

请帮忙.谢谢.


立即更新我做了其他事情:1.我在帐户控制器2上添加了注释([RequireHttps]).我为我的项目启用了SSL.2.我更新了网址并将Google控制台中的网址重定向到https

尝试使用Google登录后,在我选择了我的Google帐户后,它返回了相同的access_denied.

如果Google的回复可以提供更详细的信息会更好.

oauth google-oauth asp.net-mvc-5

13
推荐指数
1
解决办法
7443
查看次数

Facebook OAuth突然停止工作

我昨天注意到我的网站登录已停止工作.

在过去的两个月里,这一直很有效,据我所知,我没有改变任何东西.我已尝试过以下链接,例如: - 以及更多......

ASP.NET MVC5 OWIN Facebook身份验证突然无法正常工作

我注意到Stack Overflow Facebook auth也停止了工作.

有没有人注意到这一点并找到了解决办法?值得注意的是我正在使用azure app服务来托管.但是当我使用localhost时也会发现这个问题.

我目前的设置看起来像这样......

在Startup.Auth.cs中

var facebookOptions = new Microsoft.Owin.Security.Facebook.FacebookAuthenticationOptions()
{
    AppId = "xxxxxxxxxxxxx",
    AppSecret = "xxxxxxxxxxxx"
};
facebookOptions.Scope.Add("email");
app.UseFacebookAuthentication(facebookOptions);
Run Code Online (Sandbox Code Playgroud)

在下面的方法,loginInfonull每一次.

[AllowAnonymous]
public async Task<ActionResult> ExternalLoginCallback(string returnUrl)
{
    var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
    if (loginInfo == null)
    {
        return RedirectToAction("Login");
    }
Run Code Online (Sandbox Code Playgroud)

我还从一个不同的帖子建议中添加了一个"WAKEUP"会话,fb auth之前失败了一次,这次修复了这个问题,但它已经回来了.

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public ActionResult ExternalLogin(string provider, string returnUrl)
{
    Session["WAKEUP"] = "NOW!";

    // Request a redirect to the external login provider …
Run Code Online (Sandbox Code Playgroud)

model-view-controller facebook oauth facebook-graph-api owin

12
推荐指数
2
解决办法
3893
查看次数

在MVC 4 webapplication中,外部登录不适用于facebook

我注意到2017年3月27日Facebook GRAPH API到期后,我的Facebook应用程序无法提供对我的Web应用程序的访问.主要OAuthWebSecurity是无法从facebook图形API获取登录状态,我已经完成了开发人员组中的错误报告.但他们没有提供解决方案.我得到了一个解决方案,NopCommerce在此链接中提供.但是我没有得到任何完美的解决方案MVC 4.

我已经通过了这个链接,他们的系统在接近MVC 5,但是我需要在解决MVC4这一点,提OWIN不支持MVC4VS 2012 那么,如何解决这个问题.自从过去一周以来,我一直在经历这个问题.

主要是这段代码中发生异常

AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication(Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
Run Code Online (Sandbox Code Playgroud)

它返回IsSuccessful为false,其余参数也为null.

我研究称Facebook已经改变了API的返回类型string,以JSON因此,如何发展自己的代码来获取那些JSON完全吻合.谢谢.

更新: 此问题仍未得到答复.有人在这里帮助我.

facebook facebook-graph-api facebook-authentication asp.net-mvc-4 facebook-apps

10
推荐指数
2
解决办法
1226
查看次数

版本弃用Facebook Graph API v2.2

我们的Facebook登录目前无效.我们收到了Facebook Developer Portal的消息:

"应用程序名称"目前可以访问Graph API v2.2,该版本将于2017年3月27日达到其2年生命周期的终点.为确保平稳过渡,请将所有调用迁移到Graph API v2.3或更高版本.

要检查您的应用是否会受到此升级的影响,您可以使用版本升级工具.这将显示哪些呼叫(如果有)受此更改影响以及更新版本中的任何替换呼叫.如果您没有看到任何电话,则您的应用可能不会受到此更改的影响.

您还可以使用我们的更改日志查看所有Graph API版本中的完整更改列表.

我们正在使用ASP.NET MVC 5,我们正在使用或认证如下:

var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
            {
                AppId = "****",
                AppSecret = "****",
                AuthenticationType = "Facebook",
                SignInAsAuthenticationType = "ExternalCookie",
                Provider = new FacebookAuthenticationProvider
                {
                    OnAuthenticated = async ctx => ctx.Identity.AddClaim(new Claim(ClaimTypes.Email, ctx.User["email"].ToString()))
                }
            };

            facebookAuthenticationOptions.Scope.Add("email");
Run Code Online (Sandbox Code Playgroud)

但今天,我们的登录信息对象在ExternalLoginCallback中为null:

        [HttpGet]
        [AllowAnonymous]
        [RequireHttps]
        public async Task<ActionResult> ExternalLoginCallback(string returnUrl = null)
        {
            try
            {
                var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();
                if (loginInfo == null)
                {
                    return RedirectToAction("Login");
                }
... more code here...
Run Code Online (Sandbox Code Playgroud)

在Facebook开发.Portal我们的API版本是2.3 …

asp.net-mvc facebook facebook-graph-api asp.net-mvc-5

5
推荐指数
1
解决办法
1713
查看次数

使用Facebook登录的新#access_denied(ASP.NET MVC)

我在我的网站上遇到了Facebook登录的奇怪问题.这是一个全新的东西,Facebook登录一直正常工作,它仍然在我的Android和iOS应用程序上工作.

我在网站上有一个链接:

 http://myURL/api/Account/ExternalLogin?provider=Facebook&response_type=token&client_id=self&redirect_uri=http://myURL/Home/Register?
Run Code Online (Sandbox Code Playgroud)

显然在developer.facebook.com中,我已经设置了类似的东西,在OAUTH ADDRESS中我有:

 http://myURL
 http://myURL/Home/Register
 http://myURL/Home/Register?
Run Code Online (Sandbox Code Playgroud)

我也有我的localhost(几天前工作正常)

我的应用需要此访问权限:

       var facebookAuthenticationOptions = new FacebookAuthenticationOptions()
        {
            AppId = "[Hidden For Security Reason]",
            AppSecret = "[Hidden For Security Reason]"
        };
        facebookAuthenticationOptions.Scope.Add("email");
        facebookAuthenticationOptions.Scope.Add("user_friends");
        facebookAuthenticationOptions.Scope.Add("user_birthday");
        app.UseFacebookAuthentication(facebookAuthenticationOptions);
Run Code Online (Sandbox Code Playgroud)

我的图形api版本是v2.6

当我点击链接时,我进入了facebook,我将凭据放入其中,然后将其返回到myURL#access_denied.

有人有任何线索吗?

asp.net facebook facebook-graph-api facebook-login

4
推荐指数
1
解决办法
2275
查看次数