Class: OmniAuth::Strategies::Renren
- Inherits:
-
OAuth2
- Object
- OAuth2
- OmniAuth::Strategies::Renren
- Defined in:
- lib/omniauth_china/strategies/renren.rb
Overview
Authenticate to Renren utilizing OAuth 2.0 and retrieve basic user information.
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #build_access_token ⇒ Object
-
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Renren
constructor
A new instance of Renren.
- #renren_session ⇒ Object
- #request_phase ⇒ Object
- #session_key ⇒ Object
- #signed_params ⇒ Object
- #user_data ⇒ Object
- #user_info ⇒ Object
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 25 26 |
# File 'lib/omniauth_china/strategies/renren.rb', line 18 def initialize(app, client_id = nil, client_secret = nil, = {}, &block) = { :site => "http://graph.renren.com/", :authorize_url => "/oauth/authorize", :access_token_url => "/oauth/token" } super(app, :renren, client_id, client_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/omniauth_china/strategies/renren.rb', line 78 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
54 55 56 57 58 59 60 |
# File 'lib/omniauth_china/strategies/renren.rb', line 54 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
62 63 64 65 66 67 68 69 |
# File 'lib/omniauth_china/strategies/renren.rb', line 62 def renren_session = request.["rrs_#{client.id}"] if @renren_session ||= Rack::Utils.parse_query(request.["rrs_#{client.id}"].gsub('"', '')) else nil end end |
#request_phase ⇒ Object
49 50 51 52 |
# File 'lib/omniauth_china/strategies/renren.rb', line 49 def request_phase [:scope] ||= "publish_feed" super end |
#session_key ⇒ Object
45 46 47 |
# File 'lib/omniauth_china/strategies/renren.rb', line 45 def session_key @session_key ||= MultiJson.decode(@access_token.get('/renren_api/session_key')) end |
#signed_params ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/omniauth_china/strategies/renren.rb', line 32 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
28 29 30 |
# File 'lib/omniauth_china/strategies/renren.rb', line 28 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
71 72 73 74 75 76 |
# File 'lib/omniauth_china/strategies/renren.rb', line 71 def user_info { 'name' => user_data["name"], 'image' => user_data["tinyurl"] } end |