Class: Devise::FacebookConsumerController

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

Instance Method Summary collapse

Methods included from DeviseOauth2Facebook::FacebookConsumerHelper

#facebook_client

Instance Method Details

#authObject



5
6
7
8
# File 'app/controllers/devise/facebook_consumer_controller.rb', line 5

def auth
  url = send("#{resource_name}_fb_callback_url".to_sym)
  redirect_to facebook_client.authorization.authorize_url(:redirect_uri => url , :scope => Devise.facebook_permissions)
end

#callbackObject



10
11
12
13
14
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
45
46
47
# File 'app/controllers/devise/facebook_consumer_controller.rb', line 10

def callback
  # if resource_class.respond_to?(:serialize_into_cookie)
  #   User.first.remember_me!
  #   cookies.signed["remember_#{resource_name}_token"] = {
  #     :value => User.first.class.serialize_into_cookie(User.first),
  #     :expires => User.first.remember_expires_at,
  #     :path => "/"
  #   }
  # end
  # sign_in_and_redirect(resource_name, User.first)
  # set_flash_message :notice, :signed_in
  # return
  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!

  # Rails.logger.info "FB USER:"
  # Rails.logger.info fb_user.inspect

  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
  (resource_name, resource)
end