Class: Authorizme::Provider::Facebook

Inherits:
Object
  • Object
show all
Defined in:
lib/authorizme/provider/facebook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Facebook

Returns a new instance of Facebook.



9
10
11
12
# File 'lib/authorizme/provider/facebook.rb', line 9

def initialize(options={})
  @options = options
  init_client
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/authorizme/provider/facebook.rb', line 7

def options
  @options
end

Instance Method Details

#authorize_with_code(code, redirect_uri) ⇒ Object



51
52
53
54
# File 'lib/authorizme/provider/facebook.rb', line 51

def authorize_with_code code, redirect_uri
  @access_token = @client.authorization.process_callback(code, :redirect_uri => redirect_uri)
  return @access_token != nil
end

#authorize_with_signed_request(signed_request) ⇒ Object



56
57
58
59
60
61
# File 'lib/authorizme/provider/facebook.rb', line 56

def authorize_with_signed_request signed_request
  @signed_request_data = FBGraph::Canvas.parse_signed_request(@options[:client_secret], signed_request)
  @access_token = @signed_request_data["oauth_token"] if @signed_request_data["oauth_token"]
  @client.set_token @access_token if @client
  return @access_token != nil
end

#get_access_tokenObject



18
19
20
# File 'lib/authorizme/provider/facebook.rb', line 18

def get_access_token
  @access_token
end

#get_clientObject



14
15
16
# File 'lib/authorizme/provider/facebook.rb', line 14

def get_client
  @client
end

#get_dialog_authorize_url(callback_url, scope) ⇒ Object



69
70
71
# File 'lib/authorizme/provider/facebook.rb', line 69

def get_dialog_authorize_url callback_url, scope
  "https://www.facebook.com/dialog/oauth/?client_id=#{@options[:client_id]}&redirect_uri=#{CGI.escape(callback_url)}&scope=#{scope}"
end

#get_popup_authorize_url(callback_url, scope) ⇒ Object



63
64
65
66
67
# File 'lib/authorizme/provider/facebook.rb', line 63

def get_popup_authorize_url callback_url, scope
  @client.authorization.authorize_url(:redirect_uri => callback_url, 
                                                :scope => scope, 
                                                :display => "popup")
end

#get_signed_request_dataObject



43
44
45
46
47
48
49
# File 'lib/authorizme/provider/facebook.rb', line 43

def get_signed_request_data
  if @signed_request_data 
    return @signed_request_data
  else
    return nil
  end
end

#get_userObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/authorizme/provider/facebook.rb', line 26

def get_user
  user_json = get_user_json
  if user_json
    if @options[:image_size]
      width = @options[:image_size][:width]
      height = @options[:image_size][:height]
      image_url = "https://graph.facebook.com/#{user_json.id}/picture?width=#{width}&height=#{height}" 
    else
      image_url = "https://graph.facebook.com/#{user_json.id}/picture?type=large" 
    end
    attributes = {first_name: user_json.first_name, last_name: user_json.last_name, image_url: image_url, email: user_json.email}
    return attributes
  else
    return nil
  end
end

#get_user_jsonObject



22
23
24
# File 'lib/authorizme/provider/facebook.rb', line 22

def get_user_json
  @user_json ||= @client.selection.me.info! if @access_token
end