0

I'm trying to make a canvas facebook app using rails 3 and oauth2. It kind of works fine following the steps here https://github.com/intridea/oauth2

So when I go to the app in FB, it triggers the methods set by oauth2 BUT, it asks the user to give the permissions OUTSIDE of the canvas, it goes out of FB. Then when the user gives permission it goes where it is supposed to go in the application but again everything OUTSIDE FB.

After giving the permissions if I go to the app inside FB then it shows the app within the canvas.

Anyone familiar with this?

Cheers.

Pod
  • 928
  • 1
  • 10
  • 30

3 Answers3

0

As I know, the page, where you give permissions to app should be outside of app page. And if you want for than be redirected to your FB app page, you should use

access_token = client.web_server.get_access_token(params[:code], :redirect_uri => redirect_uri)

def redirect_uri
    uri = URI.parse(request.url)
    uri.path = '/fbcanvas'
    uri.query = nil
    uri.to_s
end

redirect_uri method is specially used here, so when you are redirected from your fb app page, you'll return there, and if you are redirected from your site itself, you'll return to your site.

sandrew
  • 3,109
  • 5
  • 19
  • 29
  • Hi, thanks for checking. I actually get OAuth2::HTTPError (Received HTTP 400 during request.) changing redirect that way. – Pod Nov 30 '10 at 22:52
  • What is the /fvcanvas you suggest? Something particular to your app? Since I don't have such a route. – Pod Nov 30 '10 at 23:18
  • /fbcanvas is just a my root address of canvas pages. OAuth2::HTTPError or OAuth2::AccessDenied mean that you are not authorized, in rescuing them I redrect user to fb auth page. I think, you should read closer FB docs, also view oauth2 gem sources, they are rather small, but help to uderstand what to do in the lack of docs. – sandrew Dec 01 '10 at 22:50
0

I actually changed gems.

What I'm using now is devise_oauth2_canvas_facebook gem. https://github.com/ninajansen/devise_oauth2_canvas_facebook

It works together with devise and fbgraph and it worked pretty much out of the box, so I recommend that for canvas fb apps.

And everything stays inside the fb canvas :-)

Regards.

Pod
  • 928
  • 1
  • 10
  • 30
0

I had the same problem and answered my own question. You need to add the code below to application_contoller as per the OmniAuth Overview wiki page. But take care to use request.env["HTTP_REFERER"] rather than request.full_path.

def authenticate_user!
  if !current_user
    # This should work, but session is lost. See https://github.com/plataformatec/devise/issues/1357
    # session[:return_to] = request.fullpath
    redirect_to user_omniauth_authorize_path(:google_apps, :origin => request.env["HTTP_REFERER"])
  end
end   

def after_sign_in_path_for(resource)
  # This should work, but session is lost. See https://github.com/plataformatec/devise/issues/1357
  # return_to = session[:return_to]
  # session[:return_to] = nil
  return_to = request.env['omniauth.origin']
  stored_location_for(resource) || return_to || root_path  
end 
Community
  • 1
  • 1