Class: OmniAuth::Strategies::Renren
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Renren
show all
- Defined in:
- lib/omniauth/strategies/oauth2/renren.rb
Overview
Authenticate to Renren utilizing OAuth 2.0 and retrieve
basic user information.
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) ⇒ Renren
Returns a new instance of Renren.
18
19
20
21
22
23
24
|
# File 'lib/omniauth/strategies/oauth2/renren.rb', line 18
def initialize(app, client_id=nil, client_secret=nil, options={}, &block)
client_options = {
:authorize_url => 'http://graph.renren.com/oauth/authorize',
:token_url => 'http://graph.renren.com/oauth/token',
}
super(app, :renren, 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/renren.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
|
#build_access_token ⇒ Object
64
65
66
67
68
69
70
|
# File 'lib/omniauth/strategies/oauth2/renren.rb', line 64
def build_access_token
if renren_session.nil? || renrensession.empty?
super
else
@access_token = ::OAuth2::AccessToken.new(client, renren_session['access_token'])
end
end
|
#renren_session ⇒ Object
72
73
74
75
76
77
78
79
|
# File 'lib/omniauth/strategies/oauth2/renren.rb', line 72
def renren_session
session_cookie = request.cookies["rrs_#{client.id}"]
if session_cookie
@renren_session ||= Rack::Utils.parse_query(request.cookies["rrs_#{client.id}"].gsub('"', ''))
else
nil
end
end
|
#request_phase ⇒ Object
59
60
61
62
|
# File 'lib/omniauth/strategies/oauth2/renren.rb', line 59
def request_phase
options[:scope] ||= 'publish_feed'
super
end
|
#session_key ⇒ Object
55
56
57
|
# File 'lib/omniauth/strategies/oauth2/renren.rb', line 55
def session_key
@session_key ||= MultiJson.decode(@access_token.get('/renren_api/session_key'))
end
|
#signed_params ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/omniauth/strategies/oauth2/renren.rb', line 42
def signed_params
params = {}
params[:api_key] = client.id
params[:method] = 'users.getInfo'
params[:call_id] = Time.now.to_i
params[:format] = 'json'
params[:v] = '1.0'
params[:uids] = session_key['user']['id']
params[:session_key] = session_key['renren_token']['session_key']
params[:sig] = Digest::MD5.hexdigest(params.map{|k,v| "#{k}=#{v}"}.sort.join + client.secret)
params
end
|
#user_data ⇒ Object
38
39
40
|
# File 'lib/omniauth/strategies/oauth2/renren.rb', line 38
def user_data
@data ||= MultiJson.decode(Net::HTTP.post_form(URI.parse('http://api.renren.com/restserver.do'), signed_params).body)[0]
end
|
#user_info ⇒ Object
81
82
83
84
85
86
|
# File 'lib/omniauth/strategies/oauth2/renren.rb', line 81
def user_info
{
'name' => user_data['name'],
'image' => user_data['tinyurl'],
}
end
|