-
Notifications
You must be signed in to change notification settings - Fork 95
/
oauth_connect.rb
35 lines (29 loc) · 1006 Bytes
/
oauth_connect.rb
1
2
3
4
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
31
32
33
34
35
module OauthConnect
def oauth_client
OAuth2::Client.new(FACEBOOK_CONSUMER_KEY, FACEBOOK_CONSUMER_SECRET, :site => 'https://graph.facebook.com')
end
def twitter_oauth_client
TwitterOAuth::Client.new(:consumer_key => TWITTER_CONSUMER_KEY,:consumer_secret => TWITTER_CONSUMER_SECRET)
end
def check_is_dev(default_host)
return "spotus.local:3000" if Rails.env.development?
default_host
end
def fb_access_token(code)
begin
oauth_client.web_server.get_access_token(code, :redirect_uri => "http://" + check_is_dev(APP_CONFIG[:default_host]) + "/auth/facebook/callback") # | redirect_uri(uri)
rescue
return false
end
end
def twitter_access_token()
begin
twitter_oauth_client.request_token(:oauth_callback => "http://" + check_is_dev(APP_CONFIG[:default_host]) + "/auth/twitter/callback")
rescue
return false
end
end
def redirect_uri
"http://" + check_is_dev(APP_CONFIG[:default_host]) + "/auth/facebook/callback"
end
end