GameScripting
GameScripting

Reputation: 17012

Facebook authentication response parameters are wrong -> infinite request loop

I an new to the facebook API and after some work I encountered a problem. First, I am using the facebook SDK for communication with the facebook APIs.

In my app settings I chose that the response of the OAuth dialog should be query string instead of URI fragment.

enter image description here

On my server I got the following code:

void Page_Load()
{
    string url = Request.Url.AbsoluteUri;
    Facebook.FacebookOAuthResult result = null;        
    if (!Facebook.FacebookOAuthResult.TryParse(url, out result))
    {
        string redirectUrl = PivotServer.Helpers.GetFacebookOAuthUrl();
        Response.Redirect(redirectUrl);
    }
}

And thats my helper method:

    public static string GetFacebookOAuthUrl()
    {
        FacebookOAuthClient oauth = new FacebookOAuthClient
        {
            AppId = "149637255147166",
            AppSecret = "xxx",
            RedirectUri = new Uri("http://mydomain.com/")
        };

        var param = new Dictionary<string, object>
        {
            { "response_type", "token" },
            { "display", "popup" }
        };

        Uri url = oauth.GetLoginUrl(param);

        return url.AbsoluteUri;
    }

I ran my page on a web server (IIS). When I open the page the first time I am asked to log in to facebook, which is alright, but then I ran into an infinity loop, because the Auth Token Parameter (from facebook) is an URI fragment instead if a query string (which I wanted (see picture above)). The response URI looks like

http://mydomain.com/#access_token=AAACIGCNwLp4BAMccSoliF5EMGJm0NPldv5GpmBPIm9z7rRuSkiia7BM0uhEn1V88c8uOlWOfGc3C8sFC9tq90Ma0OwIm0tWLNU5BBAZDZD&expires_in=0&base_domain=mydomain.com

instead of

http://mydomain.com/?code=AAACIGCNwLp4BAMccSoliF5EMGJm0NPldv5GpmBPIm9z7rRuSkiia7BM0uhEn1V88c8uOlWOfGc3C8sFC9tq90Ma0OwIm0tWLNU5BBAZDZD&expires_in=0&base_domain=mydomain.com

Is that a bug from the OAuth API, or what am I doing very wrong here?

Upvotes: 1

Views: 1048

Answers (2)

GameScripting
GameScripting

Reputation: 17012

It has been too easy:

var param = new Dictionary<string, object>
{
    { "response_type", "code" }, // <--- "code" instead of "token"
    { "display", "popup" }
};

Upvotes: 1

DMCS
DMCS

Reputation: 31870

It's an issue with IE. Be sure to have a p3p header in each response from your server.

Upvotes: 1

Related Questions