开发者

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开发者_JAVA技巧 I wanted. How can I authenticate user in this case ? Thanks for your answers.


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);


Have you tried enabling cookie support in facebookSettings?

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜