Class: OmniAuth::Strategies::Mailru
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Mailru
show all
- Defined in:
- lib/omniauth/strategies/oauth2/mailru.rb
Overview
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) ⇒ Mailru
Returns a new instance of Mailru.
17
18
19
20
21
22
23
24
|
# File 'lib/omniauth/strategies/oauth2/mailru.rb', line 17
def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
client_options = {
:authorize_url => 'https://connect.mail.ru/oauth/authorize',
:token_url => 'https://connect.mail.ru/oauth/token',
}
@private_key = options[:private_key]
super(app, :mailru, client_id, client_secret, client_options, options, &block)
end
|
Instance Method Details
#auth_hash ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/omniauth/strategies/oauth2/mailru.rb', line 26
def auth_hash
OmniAuth::Utils.deep_merge(
super, {
'uid' => user_data['uid'],
'user_info' => user_info,
'extra' => {
'user_hash' => user_data,
},
}
)
end
|
#calculate_signature(params) ⇒ Object
43
44
45
46
|
# File 'lib/omniauth/strategies/oauth2/mailru.rb', line 43
def calculate_signature(params)
str = params['uids'] + (params.sort.collect { |c| "#{c[0]}=#{c[1]}" }).join('') + @private_key
Digest::MD5.hexdigest(str)
end
|
#request_phase ⇒ Object
38
39
40
41
|
# File 'lib/omniauth/strategies/oauth2/mailru.rb', line 38
def request_phase
options[:response_type] ||= 'code'
super
end
|
#user_data ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/omniauth/strategies/oauth2/mailru.rb', line 48
def user_data
request_params = {
'method' => 'users.getInfo',
'app_id' => client_id,
'session_key' => @access_token.token,
'uids' => @access_token['x_mailru_vid']
}
request_params.merge!('sig' => calculate_signature(request_params))
@data ||= MultiJson.decode(client.request(:get, 'http://www.appsmail.ru/platform/api', request_params))[0]
end
|
#user_info ⇒ Object
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/omniauth/strategies/oauth2/mailru.rb', line 60
def user_info
{
'nickname' => user_data['nick'],
'email' => user_data['email'],
'first_name' => user_data['first_name'],
'last_name' => user_data['last_name'],
'name' => "#{user_data['first_name']} #{user_data['last_name']}".strip,
'image' => @data['pic'],
'urls' => {
'Mailru' => user_data['link'],
},
}
end
|