Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Facebook canvas in Rails app

I'm using a before_filter to detect the signed_request query string Facebook generates when a user is referred to a canvas app.

Then, I set session[:canvas] = true and test for that when I need different app logic based on whether the user is in the canvas or on the native browser app. The problem is that if the user, for any reason, leaves the canvas and navigates to the browser-based app, the session[:canvas] variable is still set to true.

Is there a better way to detect the difference between the canvas and the native browser app?

like image 964
Slick23 Avatar asked Oct 10 '22 09:10

Slick23


1 Answers

I personally like to use an "alias" url for the Facebook app, e.g. use fb.mysite.com instead of www.mysite.com in the app settings and set things up so that the two domains point to the same place. Or something similar can be done with directories, e.g. www.mysite.com/fb/ pointing to the same place as www.mysite.com/ but giving an easy way for the code to determine if it's a direct access or from an app.

Using a session can work too, but you have to add an additional javascript check in the case you are currently in "app mode" (canvas==true). The javascript just checks to see if the page is inside an iframe, and if it is not then it redirects to something like www.mysite.com/thispage?app=0. Your pages should check for the app=0 parameter and clear the session if present (or set canvas=false). This way, if a user starts out inside Facebook but then visits your site directly, things automatically get adjusted correctly.

like image 180
Floyd Wilburn Avatar answered Oct 13 '22 11:10

Floyd Wilburn