Class: Devise::FacebookConsumerController

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

Instance Method Summary collapse

Methods included from DeviseOauth2CanvasFacebook::FacebookConsumerHelper

#facebook_client

Instance Method Details

#authObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/devise/facebook_consumer_controller.rb', line 5

def auth
  if !!params[:permission]
    scope =  Devise.facebook_permissions + ",#{params[:permission]}"
  else
    scope = Devise.facebook_permissions
  end
  url = send("#{resource_name}_fb_callback_url".to_sym)
  if params[:permission] && params[:go_back]
    url = url + "?permission=#{params[:permission]}&go_back=#{params[:go_back]}&abs_url=#{params[:abs_url]}"
  elsif params[:permission]
     url = url + "?permission=#{params[:permission]}"
  elsif params[:go_back]
     url = url + "?go_back=#{params[:go_back]}"
  end
  
  if params[:go_back] && params[:abs_url]
    url = url + "&abs_url=#{params[:abs_url]}"
  end
  
  uri = facebook_client.authorization.authorize_url(:redirect_uri => url, :scope => scope)
  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



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/devise/facebook_consumer_controller.rb', line 32

def callback
  url = send("#{resource_name}_fb_callback_url".to_sym)
  if params[:permission] && params[:go_back]
    url = url + "?permission=#{params[:permission]}&go_back=#{CGI::escape(params[:go_back])}"
  elsif params[:permission]
    url = url + "?permission=#{params[:permission]}"
  elsif params[:go_back]
    url = url + "?go_back=#{CGI::escape(params[:go_back])}"
  end
  
  if params[:go_back] && params[:abs_url]
    url = url + "&abs_url=#{params[:abs_url]}"
  end
    
  client = facebook_client
  client.authorization.process_callback(params[:code], :redirect_uri => url)
  
  token = client.access_token
  
  fb_user = client.selection.me.info!
  
  if !!params[:permission]
    permissions = Devise.facebook_permissions + ",#{params[:permission]}"
  else
    permissions = Devise.facebook_permissions
  end
    
  options = {:permissions => permissions}
  
  resource = resource_class.find_with_facebook_user(fb_user, token, client, options)
  unless resource
    resource = resource_class.create_with_facebook_user(fb_user, token, client, options)
  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)
    if params[:go_back] && !!params[:abs_url] && params[:abs_url] != "0"
      if params[:abs_url] == "1"
        redirect_to params[:go_back]
      elsif !!params[:go_back].match(/\?/)
        redirect_to params[:go_back] + "&abs_url=#{params[:abs_url]}"
      else
        redirect_to params[:go_back] + "?abs_url=#{params[:abs_url]}"
      end
    elsif params[:go_back]
      redirect_to Devise.facebook_canvas_url + params[:go_back]
    else
      redirect_to Devise.facebook_canvas_url
    end
  else
    (resource_name, resource)
  end
end