challah-facebook 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,14 +12,6 @@ module Challah
|
|
12
12
|
client.access_token!(:client_auth_body).to_s
|
13
13
|
end
|
14
14
|
|
15
|
-
def self.get_access_token_from_cookies(cookies_hash)
|
16
|
-
fb_auth = new(Facebook.options).auth
|
17
|
-
fb_auth.from_cookie(cookies_hash)
|
18
|
-
fb_auth.access_token.to_s
|
19
|
-
rescue
|
20
|
-
nil
|
21
|
-
end
|
22
|
-
|
23
15
|
def self.get_extended_token(access_token)
|
24
16
|
fb_auth = new(Facebook.options).auth
|
25
17
|
fb_auth.exchange_token!(access_token)
|
@@ -5,6 +5,60 @@ module Challah
|
|
5
5
|
def self.mode
|
6
6
|
"koala"
|
7
7
|
end
|
8
|
+
|
9
|
+
def self.get_access_token_for_oauth_code(code, callback_uri)
|
10
|
+
auth = new(Facebook.options).auth(callback_uri)
|
11
|
+
auth.get_access_token(code)
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.get_extended_token(access_token)
|
15
|
+
auth = new(Facebook.options).auth
|
16
|
+
token_hash = auth.exchange_access_token_info(access_token)
|
17
|
+
token_hash.fetch('access_token')
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.get_facebook_uid_from_access_token(access_token)
|
21
|
+
fb_user = get_user_object_from_access_token(access_token)
|
22
|
+
|
23
|
+
if fb_user
|
24
|
+
return fb_user.fetch('id').to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
nil
|
28
|
+
rescue
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.get_user_info_from_access_token(access_token)
|
33
|
+
result = {}
|
34
|
+
|
35
|
+
fb_user = get_user_object_from_access_token(access_token)
|
36
|
+
|
37
|
+
Facebook.user_fields.each do |field|
|
38
|
+
if fb_user.has_key?(field)
|
39
|
+
result[field] = fb_user[field]
|
40
|
+
else
|
41
|
+
result[field] = nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
result
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.get_user_object_from_access_token(access_token)
|
49
|
+
graph = ::Koala::Facebook::API.new(access_token)
|
50
|
+
graph.get_object('me')
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.get_authorization_url(callback_uri, permissions = nil)
|
54
|
+
scope = Facebook.permissions if permissions.nil?
|
55
|
+
auth = new(Facebook.options).auth(callback_uri)
|
56
|
+
auth.url_for_oauth_code(permissions: scope)
|
57
|
+
end
|
58
|
+
|
59
|
+
def auth(callback_url = nil)
|
60
|
+
@auth ||= ::Koala::Facebook::OAuth.new(app_id, app_secret, callback_url)
|
61
|
+
end
|
8
62
|
end
|
9
63
|
end
|
10
64
|
end
|
data/lib/challah/facebook.rb
CHANGED
@@ -10,7 +10,7 @@ module Challah
|
|
10
10
|
@options ||= {
|
11
11
|
app_id: ENV['FACEBOOK_APP_ID'],
|
12
12
|
app_secret: ENV['FACEBOOK_SECRET'],
|
13
|
-
permissions: ENV['FACEBOOK_PERMISSIONS'].to_s.split(','),
|
13
|
+
permissions: (ENV['FACEBOOK_PERMISSIONS'] || 'email').to_s.split(','),
|
14
14
|
user_fields: %w( first_name last_name email )
|
15
15
|
}
|
16
16
|
end
|