Class: OmniAuth::Strategies::Foursquare
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Foursquare
show all
- Defined in:
- lib/omniauth/strategies/oauth2/foursquare.rb
Instance Attribute Summary
Attributes inherited from OAuth2
#client_id, #client_options, #client_secret, #options
Instance Method Summary
collapse
Methods inherited from OAuth2
#callback_url, #client
Constructor Details
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Foursquare
Initialize the middleware
11
12
13
14
15
16
17
18
|
# File 'lib/omniauth/strategies/oauth2/foursquare.rb', line 11
def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
options[:sign_in] ||= true
client_options = {
:authorize_url => authorize_url(options),
:token_url => 'https://foursquare.com/oauth2/access_token',
}
super(app, :foursquare, client_id, client_secret, client_options, options, &block)
end
|
Instance Method Details
#auth_hash ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/omniauth/strategies/oauth2/foursquare.rb', line 20
def auth_hash
OmniAuth::Utils.deep_merge(
super, {
'uid' => user_data['response']['user']['id'],
'user_info' => user_info,
'extra' => {
'user_hash' => user_data['response']['user'],
},
}
)
end
|
#authorize_url(options) ⇒ Object
32
33
34
|
# File 'lib/omniauth/strategies/oauth2/foursquare.rb', line 32
def authorize_url(options)
"https://foursquare.com/#{'mobile/' if options[:mobile]}oauth2/#{options[:sign_in] ? 'authenticate' : 'authorize'}"
end
|
#callback_phase ⇒ Object
45
46
47
48
|
# File 'lib/omniauth/strategies/oauth2/foursquare.rb', line 45
def callback_phase
options[:grant_type] ||= 'authorization_code'
super
end
|
#request_phase ⇒ Object
40
41
42
43
|
# File 'lib/omniauth/strategies/oauth2/foursquare.rb', line 40
def request_phase
options[:response_type] ||= 'code'
super
end
|
#user_data ⇒ Object
36
37
38
|
# File 'lib/omniauth/strategies/oauth2/foursquare.rb', line 36
def user_data
@data ||= MultiJson.decode(@access_token.get('https://api.foursquare.com/v2/users/self', { :params => { 'oauth_token' => @access_token.token } }).body)
end
|
#user_info ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
|
# File 'lib/omniauth/strategies/oauth2/foursquare.rb', line 50
def user_info
{
'nickname' => user_data['response']['user']['contact']['twitter'],
'first_name' => user_data['response']['user']['firstName'],
'last_name' => user_data['response']['user']['lastName'],
'email' => user_data['response']['user']['contact']['email'],
'name' => "#{user_data['response']['user']['firstName']} #{user_data['response']['user']['lastName']}".strip,
'image' => user_data['response']['user']['photo'],
'phone' => user_data['response']['user']['contact']['phone'],
}
end
|