1

Closed

Add Helpers for OAuth functions

description

We should include a helper class that supports OAuth functions such as exchanging session keys to access tokens.
Closed Jan 9, 2011 at 9:00 PM by ntotten

comments

prabirshrestha wrote Jan 7, 2011 at 8:26 AM

Here is the related gist we are working on at the moment. https://gist.github.com/769251

prabirshrestha wrote Jan 7, 2011 at 6:48 PM

Exchanging code for access token has been added to the latest source code (changeset : 743614971975 http://facebooksdk.codeplex.com/SourceControl/changeset/changes/743614971975)

Here is a sample code on how to use it.

var oauth = new FacebookOAuthClientAuthorizer { ClientId = "appId" };
dynamic result = oauth.ExchangeCodeForAccessToken("code", null);
var accessToken = result.access_token;
var expires = result.expires; // In case the scope was "offline_access" expires is not available.

prabirshrestha wrote Jan 8, 2011 at 6:16 AM

Async version can also be used from changeset : 2b3d9fd1fca0 (http://facebooksdk.codeplex.com/SourceControl/changeset/changes/2b3d9fd1fca0)

var oauth = new FacebookOAuthClientAuthorizer
            {
                ClientId = "client_id",
                ClientSecret = "client_secret",
                RedirectUri = new Uri("http://www.facebook.com/connect/login_success.html")
            };
oauth.ExchangeCodeForAccessTokenAsync("code", null,
r =>
{
    if (r.Error == null)
    {
        dynamic result = r.Result;
        var accessToken = result.access_token;
        var expires = result.expires; // In case the scope was "offline_access" expires is not available. 
    }
});