10

I have the following code where its grabbing First/Last name. I realize that email is an extended permission, but what would I need to modify to request extended permissions?

How do I get the email of an authenticated Facebook user through the DotNetOpenAuth?

        fbClient = new FacebookClient
        {
            ClientIdentifier = ConfigurationManager.AppSettings["facebookAppID"],
            ClientSecret = ConfigurationManager.AppSettings["facebookAppSecret"],
        };

        IAuthorizationState authorization = fbClient.ProcessUserAuthorization();
        if (authorization == null)
        {
            // Kick off authorization request
            fbClient.RequestUserAuthorization();

        }
        else
        {
            var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    var graph = FacebookGraph.Deserialize(responseStream);

                    // unique id for facebook based on their ID
                    FormsAuthentication.SetAuthCookie("fb-" + graph.Id, true);

                    return RedirectToAction("Index", "Admin");
                }
            }
        }

        return View("LogOn");
sakibmoon
  • 1,921
  • 3
  • 19
  • 32
aherrick
  • 18,488
  • 29
  • 100
  • 168

2 Answers2

11

Add the following bits:

            var scope = new List<string>();
            scope.Add("email");
            fbClient.RequestUserAuthorization(scope);
sakibmoon
  • 1,921
  • 3
  • 19
  • 32
aherrick
  • 18,488
  • 29
  • 100
  • 168
  • 1
    yep - scope are facebook permissions – aherrick Mar 18 '11 at 21:18
  • Note that in newer version of DotNetOpenAuth.ApplicationBlock, ClientSecret doesn't exist. It should now be as follows: FacebookClient fbClient = new FacebookClient { ClientIdentifier = "appId", ClientCredentialApplicator = ClientCredentialApplicator.PostParameter("appSecret") }; – Gautam Jain Nov 14 '15 at 06:53
1

If you are using VS2012 built in oauth providers you just need to update your oauth package. See the last post on the following link: http://forums.asp.net/t/1847724.aspx/1. The only email I can't retrieve is MS Live. Currently I use facebook, google, and yahoo.

MarkusR
  • 81
  • 1
  • 3