无法通过ASP MVC5获取电子邮件或公开个人资料facebook

时间:2015-07-25 10:29:57

标签: facebook oauth asp.net-mvc-5

我使用MVC5来获取公共配置文件用户,但我只获取用户的ID和DisplayName。我研究了多种方法但没有结果。这是我的设置代码段:

var options = new FacebookAuthenticationOptions
        {
            AppId = "xxx",
            AppSecret = "xxx",
            SignInAsAuthenticationType = "ExternalCookie",
            Provider = new FacebookAuthenticationProvider
            {
                OnAuthenticated = async context =>
                {
                    context.Identity.AddClaim(new System.Security.Claims.Claim("FacebookAccessToken", context.AccessToken));
                }
            }
        };
        options.Scope.Add("email");
        options.Scope.Add("public_profile");
        app.UseFacebookAuthentication(options);

我将请求结果称为行动

public async Task<ActionResult> Index()
    {
        var userDisplayModel = new UserDisplayModel();

        var authenticateResult = await AuthenticationManager.AuthenticateAsync("ExternalCookie");
        if (authenticateResult != null)
        {
            userDisplayModel = new UserDisplayModel()
            {
                DisplayName = authenticateResult.Identity.Claims.FirstOrDefault(t => t.Type == ClaimTypes.Name).Value
            };
        }

        return View(userDisplayModel);
    }

0 个答案:

没有答案