a1ex07
a1ex07

Reputation: 37364

Facebook C# Iframe Authorization

I have an IFrame Facebook application that uses Facebook C# SDK. I also use jquery and load some page components asynchronously. For example, I call the following javascript from main page(at this point user is authenticated)

$.ajax({            
    type: "POST",
    url: "Ajax/GetMyBalance.aspx",        
    datatype: 'text',
    success: function (html) {
        $('#balance_div').html(html);
    }
    });

The problem is that in GetMyBalance.aspx:PageLoad the user is not authenticated. I tried adding

 FacebookApp app = new FacebookApp();
 CanvasAuthorizer auth = new CanvasAuthorizer(app);
 if (!auth.IsAuthorized()) // always true when page is loaded first time
 {
    var url = auth.GetLoginUrl(new HttpRequestWrapper(Request));
    var content = CanvasUrlBuilder.GetCanvasRedirectHtml(url);
    Response.ContentType = "text/html";
    Response.Write(content);
    Response.End();
 }

to GetMyBalance.aspx:PageLoad ; it did authenticate the user, but it also redirected browser to Myapp/Ajax/GetMyBalance.aspx which might make sense, but it's absolutely not what I wanted. How can I authenticate user in this case ? Thanks for your answers.

Upvotes: 0

Views: 1250

Answers (3)

zozzancs
zozzancs

Reputation: 155

Well, cookieSupport does not seem to be a valid property:

"Parser Error Message: Unrecognized attribute 'cookieSupport'. Note that attribute names are case-sensitive."

--- update ---

My apologies, I found this: http://facebooksdk.codeplex.com/releases/view/59012

At SDK 4.2.1 cookieSupport is automatic, that is why I got the error

Upvotes: 0

Pat James
Pat James

Reputation: 4348

You can do it with no cookies. Set cookieSupport = false in the SDK settings and initialize the Javascript client library with cookie=false. Then get the auth token using the Javascript client library before you post, pass the auth token up to the server, and use it to instantiate your FacebookApp instance.

        FB.getLoginStatus(function (response) {
          if (response.session) {
            $('#AuthToken').val(response.session.access_token);
            $('form').ajaxSubmit(options);
            return false;
          } else {
            // not logged in, prompt them to retry
            return false;
          }
        }, true);

Upvotes: 1

el_tone
el_tone

Reputation: 1192

Have you tried enabling cookie support in facebookSettings?

<facebookSettings apiKey="blah" apiSecret="blah" appId="blah" cookieSupport="true" />

Upvotes: 1

Related Questions