Class: Devise::FacebookConsumerController

Inherits:
ApplicationController
  • Object
show all
Includes:
Controllers::InternalHelpers, DeviseOauth2FbCanvas::FacebookConsumerHelper
Defined in:
app/controllers/devise/facebook_consumer_controller.rb

Instance Method Summary collapse

Methods included from DeviseOauth2FbCanvas::FacebookConsumerHelper

#facebook_client

Instance Method Details

#authObject



5
6
7
8
9
10
11
12
13
# File 'app/controllers/devise/facebook_consumer_controller.rb', line 5

def auth
  url = send("#{resource_name}_fb_callback_url".to_sym)
  uri = facebook_client.authorization.authorize_url(:redirect_uri => url , :scope => Devise.facebook_permissions)
  if Devise.facebook_canvas_app
    render :layout => false, :inline => "<script type='text/javascript' charset='utf-8'>top.location.href='#{uri}';</script>"
  else
    redirect_to uri
  end
end

#callbackObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/controllers/devise/facebook_consumer_controller.rb', line 15

def callback
  url = send("#{resource_name}_fb_callback_url".to_sym)

  client = facebook_client
  client.authorization.process_callback(params[:code], :redirect_uri => url)

  token = client.access_token
  fb_user = client.selection.me.info!

  resource = resource_class.find_with_facebook_user(fb_user, token)
  unless resource
    resource = resource_class.create_with_facebook_user(fb_user, token)
  end
  if resource_class.respond_to?(:serialize_into_cookie)
    resource.remember_me!
    cookies.signed["remember_#{resource_name}_token"] = {
      :value => resource.class.serialize_into_cookie(resource),
      :expires => resource.remember_expires_at,
      :path => "/"
    }
  end
  set_flash_message :notice, :signed_in
  
  if Devise.facebook_canvas_app
    (resource_name, resource)
    redirect_to Devise.facebook_canvas_url
  else
    (resource_name, resource)
  end
end