Class: OauthMr
Instance Method Summary
collapse
Methods inherited from Oauth
#error_response, #initialize
Constructor Details
This class inherits a constructor from Oauth
Instance Method Details
#auth_request(step = :step1, add_params = nil) ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/oauth/oauth_mr.rb', line 2
def auth_request step = :step1, add_params = nil
uri = URI CONFIG[:oauth][@name][:auth][step][:uri]
params = CONFIG[:oauth][@name][:auth][:united_params].merge(CONFIG[:oauth][@name][:auth][step].except(:uri)).merge({redirect_uri: @verify_url, state: @key})
params.merge!(add_params) unless add_params.nil?
case step
when :step1
uri.query = URI.encode_www_form params
uri.to_s
when :step2
oauth_access_card_params Net::HTTP.post_form uri, params
end
end
|
#get_user_info(access_params) ⇒ Object
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/oauth/oauth_mr.rb', line 41
def get_user_info access_params
uri = URI CONFIG[:oauth][@name][:api][:get_user_info][:uri]
params = CONFIG[:oauth][@name][:api][:get_user_info][:params]
params.merge!(access_params) unless access_params.nil?
sig = Digest::MD5.hexdigest params.sort.map{|k,v| "#{k}=#{v}"}.join() + CONFIG[:oauth][@name][:auth][:step2][:client_secret] params = params.merge({sig: sig})
uri.query = URI.encode_www_form params
result = Net::HTTP.get_response uri
ActiveSupport::JSON.decode(result.body)[0]
end
|
#oauth_access_card_params(result) ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/oauth/oauth_mr.rb', line 19
def oauth_access_card_params result
begin
params = ActiveSupport::JSON.decode(result.body)
unless params['error'].present?
add_info = get_user_info({session_key: params['access_token'], uid: params['x_mailru_vid']})
{
state: :ok,
oauth_name: @name,
oauth_uid: params['x_mailru_vid'],
access_token: params['access_token'],
token_expired: (DateTime.now + params['expires_in'].second).to_s(:db),
photourl: add_info['has_pic'].to_i == 0 ? nil : add_info['pic_128']
}
else
error_response "#{params['error']}:#{params['error_description']} #{params} #{result.body}"
end
rescue Exception => error
error_response "rescue #{error.message} #{params} #{result.body} #{add_info}"
end
end
|