Search code examples
facebookasp.net-mvc-4oauthtwitter-oauthfacebook-oauth

Facebook oAuth user details with MVC 4


I am using the OAuthWebSecurity with MVC to allow users of my website to login using Facebook's oAuth. Everything works fine, and I have a test user authenticating fine.

My question is based on the details Facebook can provide. I am currently returning the user details using the following...

AuthenticationResult result = OAuthWebSecurity.VerifyAuthentication();

This will give the follwing details:

  • UserName (email)
  • ProviderUserId

I also get a ExternalData object which has:

  • UserName
  • Name
  • Gender

Do you know if it's possible to get further data, maybe DoB, photo etc?


Solution

  • Pardon me for not framing me the full answer. I am just supplying a link. Please check

    http://blue-and-orange.net/articles/facebook/displaying-facebook-user-data-in-aspnet-mvc-4/

    Everything is explained here.

    For setting permission you can go through this documentation https://developers.facebook.com/docs/facebook-login/permissions/

    if you were to request a user's email address, but never asked them for the 'email' permission, you would receive an OAuth error as show below.

    try {
    var client = new FacebookClient("my_access_token");
    dynamic result = client.Get("me/email");
    var email = (string)result.email;
    

    }

    catch (FacebookOAuthException) {
        // The access token expired or the user 
        // has not granted your app 'email' permission.
        // Handle this by redirecting the user to the
        // Facebook authenticate and ask for email permission.
    }