Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook C# SDK - Server flow authentication

I am using the Facebook C# SDK installed using NuGet to allow user's to login to my site using Facebook. In all the C# SDK documentation that I've found, the access token was obtained using the JavaScript SDK. I want to do the entire authentication flow server side without using JavaScript SDK.

  1. Where can I find good documentation or sample code for the steps I need to follow for complete server side authentication using the Facebook C# SDK?

  2. Is there any advantage of combining C# SDK and JavaScript SDK, or is it fine to stick to server side flow only?

like image 226
Pia Palackathadom Avatar asked Jul 02 '12 19:07

Pia Palackathadom


1 Answers

Server side authentication is same as client side, you redirect user to OAuth Dialog with parameters like RedirectUri and you AppId. Then user is redirected to RedirectUri with parameter code and now you make server side request to convert code to access token, thats all.

Read Doc for Server-Side Authentication on http://developers.facebook.com/docs/authentication/server-side/

How to exchange the code for a User Access Token with Facebook C# SDK?

var fb = new FacebookClient();
dynamic response = fb.Get("oauth/access_token", 
        new
        { 
            client_id = APP_ID,
            redirect_uri = "http://www.example.com/",
            client_secret = SECRET_ID,
            code = CODE
        })
//response.access_token
//response.expires
like image 123
312k1t Avatar answered Oct 03 '22 10:10

312k1t