Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook C# SDK Authorization Problem

I have an iFrame Facebook application. I am using the Facebook C# SDK, Facebook and Facebook.Web libraries.

When a user first comes to my application I create a FacebookApp object on page_load(). If the app.Session is null I create a CavasAuthorizer(app) then call Authorize().

Two problems:

First, the redirect URL that is generated by calling Authorize causes Facebook to error with a bad "next" parameter. Says the "next" parameter is not owned by the application. It looks like this:

next=http://localhost:4002/facebookredirect.axd/mygame_dev/mygame.aspx

I can edit the code in CanvasURLBuilder to make the next look like this:

next=http://localhost:4002/mygame.aspx

At this point the URL works if I cut and paste into a browser however it brings me to my second issue.

When the code runs the user is presented with a mostly empty page with a mid-sized Facebook image and a link "go to Facebook". When the user clicks on the link it then takes the user to the correct authorization page for my application.

I have a feeling these are two possibly related issues but potentially separate.

Any help here would be greatly appreciated.

-Andy

like image 345
Andrew Kaplan Avatar asked Apr 30 '26 00:04

Andrew Kaplan


1 Answers

For the first problem

Make sure the site Url in the app configuration page is set to http://apps.facebook.com/[your_app]/

alt text

For the second problem.

When you are not authorized you are redirected to the login url but you can't do it from your iframe since it will redirect the iframe and you will get a Facebook inside facebook. You should use window.top.location = ... to redirect the parent window.

EDIT

Facebook C# SDK Already does this for you when using the Mvc part of the SDK. Since you are using webforms you should use this code that is the equivalent.

protected void Page_Load(object sender, EventArgs e)
{
    var fb = new FacebookApp();
    var auth = new CanvasAuthorizer(fb);

    if (!auth.IsAuthorized())
    {
        var url = auth.GetLoginUrl(new HttpRequestWrapper(Request));

        var content = CanvasUrlBuilder.GetCanvasRedirectHtml(url);
        Response.ContentType = "text/html";
        Response.Write(content);
        Response.End();
        return;
    }

    //...Go on if authorized
}
like image 80
Carlos Muñoz Avatar answered May 01 '26 14:05

Carlos Muñoz