0

I'm building an Iframe canvas application for Facebook. I'm not using the Javascript SDK.

This is the code I'm using, and it works well in all browsers except for Safari.

protected FacebookApp app;

protected CanvasAuthorizer cauth;

Response.AddHeader("p3p", "CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""); app = new FacebookApp(); cauth = new CanvasAuthorizer(app); if (!cauth.IsAuthorized()) { myAuth auth = new myAuth(); myAuth.Authorize(app, Request, Response, perms); }

    if (cauth.Authorize())
    {

// Do my app stuff here }

public class myAuth
{
    public static void Authorize(FacebookApp fbApp, System.Web.HttpRequest request, System.Web.HttpResponse response, string perms)
    {
        Authorize(fbApp, request, response, perms, null);
    }

    public static void Authorize(FacebookApp fbApp, System.Web.HttpRequest request, System.Web.HttpResponse response, string perms, string redirectUrl)
    {
        Uri url = fbApp.GetLoginUrl();

        NameValueCollection nvc = System.Web.HttpUtility.ParseQueryString(url.Query);

        if (!string.IsNullOrEmpty(perms))
            nvc.Add("req_perms", perms);

        if (!string.IsNullOrEmpty(redirectUrl))
            nvc["next"] = GetAppRelativeUrl(redirectUrl);
        else if (request.QueryString.Count > 0)
            nvc["next"] = GetAppRelativeUrl(request.Path.Replace(request.ApplicationPath, string.Empty).Replace(request.ApplicationPath.ToLower(), string.Empty) + "?" + request.QueryString);
        else
            nvc["next"] = GetAppRelativeUrl(request.Path.Replace(request.ApplicationPath, string.Empty).Replace(request.ApplicationPath.ToLower(), string.Empty));

        UriBuilder ub = new UriBuilder(url);
        ub.Query = nvc.ToString();

        string content = CanvasUrlBuilder.GetCanvasRedirectHtml(ub.Uri);
        response.ContentType = "text/html";
        response.Write(content);
        response.End();
    }

    public static string GetAppRelativeUrl(string url)
    {
        return CanvasSettings.Current.CanvasPageUrl.ToString();
    }
}

I read about Safari not allowing third party cookies, and I figure that's where the problem lies. My question is wheter there's a way to handle this using the SDK, or what my options are.

Regards, Anders Pettersson

Anders
  • 31
  • 2

3 Answers3

0

here I am getting same problem but now I got solution for safari..

Just change validation mode in web.config

<system.web>

<pages enableViewState="true" validateRequest="false" />
<httpRuntime requestValidationMode="2.0"/>
<!--
 Enable this code if you get still problem
<sessionState cookieless="true" regenerateExpiredSessionId="true" />-->

Anant Dabhi
  • 10,864
  • 3
  • 31
  • 49
0

I've had some problems with Safari changing the case of data sent in HTTP headers... make sure any parsing/comparing you are doing is case insensitive.

Iain Ballard
  • 4,433
  • 34
  • 39
0

See here: Facebook Iframe App with multiple pages in Safari Session Variables not persisting

Community
  • 1
  • 1
Fabrice
  • 3,094
  • 3
  • 28
  • 31