title: Facebook API and Safari
body: <p><strong>Update and solution:</strong> It turns out the problem was based on a redirect I used for my dev URL, which resulted in browsers perceiving all cookies set by my page as third-party cookies. The Facebook JS API session cookie is <em>not</em> set as a third-party cookie.</p>
  
  <p>I'm working on an ASP.NET application with Facebook authentication. For this I use <a href="http://msdn.microsoft.com/en-us/windows/ee388574" rel="nofollow">Microsofts Facebook SDK</a> in combination with Facebooks Javascript API. Everything's working, except for Safari. Safaris default setting is to not accept third-party cookies, which results in:</p>
  
  <ul>
  <li>I can access the Facebook session through Javascript.</li>
  <li>I can NOT access the Facebook session server-side, because the cookie is never set and sent from Safari.</li>
  </ul>
  
  <p>This is my client-side code related to Facebook (JS):</p>
  
  <pre><code>&lt;div id="fb-root"&gt;&lt;/div&gt;    
  &lt;fb:login-button&gt;Login with Facebook&lt;/fb:login-button&gt;
  &lt;script src="http://connect.facebook.net/en_US/all.js"&gt;&lt;/script&gt;
  &lt;script&gt;
      FB.init({ appId: 'myAppId', status: true, cookie: true, xfbml: true });
      FB.Event.subscribe('auth.login', function (response) {
         if (response.session) {
             window.location.reload(); //Results in eternal reload of page
         }
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>This is my code for fetching the user id server-side (C#):</p>
  
  <pre><code>public string FacebookUserID
  {
      get
      {
          FacebookSettings settings = new FacebookSettings();
          settings.AppId = "myAppId";
          settings.AppSecret = "myAppSecret";
          FacebookApp app = new FacebookApp(settings);
          Authorizer auth = new Authorizer(app);
  
          return (auth.IsAuthorized()) ? app.Session.UserId : null;
      }
  }
  </code></pre>
  
  <p>I guess I'm not the only one with the same problem, but I've searched both the Facebook Developer forum and here and haven't found a solution. It's really more of a Safari problem than a Facebook-specific problem.</p>
  
  <p>I've been thinking about posting the user-id back to the server through GET/POST/my own cookie, but that is an ugly solution and a potential security issue.</p>
  
  <p>Any ideas?</p>