Class: OmniAuth::Strategies::Taobao
- Defined in:
- lib/omniauth/strategies/oauth2/taobao.rb
Overview
Authenticate to Renren utilizing OAuth 2.0 and retrieve basic user information.
use OmniAuth::Strategies::TaoBao, 'client_id', 'client_secret'
Instance Attribute Summary
Attributes inherited from OAuth2
#client_id, #client_options, #client_secret, #options
Instance Method Summary collapse
- #auth_hash ⇒ Object
- #generate_sign(params) ⇒ Object
-
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Taobao
constructor
A new instance of Taobao.
- #request_phase ⇒ Object
- #user_data ⇒ Object
- #user_info ⇒ Object
Methods inherited from OAuth2
Constructor Details
#initialize(app, client_id = nil, client_secret = nil, options = {}, &block) ⇒ Taobao
Returns a new instance of Taobao.
19 20 21 22 23 24 25 |
# File 'lib/omniauth/strategies/oauth2/taobao.rb', line 19 def initialize(app, client_id=nil, client_secret=nil, ={}, &block) = { :authorize_url => 'https://oauth.taobao.com/authorize', :token_url => 'https://oauth.taobao.com/token', } super(app, :taobao, client_id, client_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/omniauth/strategies/oauth2/taobao.rb', line 27 def auth_hash OmniAuth::Utils.deep_merge( super, { 'uid' => user_data['uid'], 'user_info' => user_info, 'extra' => { 'user_hash' => user_data, }, } ) end |
#generate_sign(params) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/omniauth/strategies/oauth2/taobao.rb', line 73 def generate_sign(params) # params.sort.collect { |k, v| "#{k}#{v}" } str = client_secret + params.sort {|a,b| "#{a[0]}"<=>"#{b[0]}"}.flatten.join + client_secret params['sign'] = Digest::MD5.hexdigest(str).upcase! params end |
#request_phase ⇒ Object
61 62 63 64 |
# File 'lib/omniauth/strategies/oauth2/taobao.rb', line 61 def request_phase [:state] ||= '1' super end |
#user_data ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/omniauth/strategies/oauth2/taobao.rb', line 39 def user_data # TODO to be moved in options url = 'http://gw.api.taobao.com/router/rest' query_param = { :app_key => client_id, # TODO to be moved in options # TODO add more default fields (http://my.open.taobao.com/apidoc/index.htm#categoryId:1-dataStructId:3) :fields => 'user_id,uid,nick,sex,buyer_credit,seller_credit,location,created,last_visit,birthday,type,status,alipay_no,alipay_account,alipay_account,email,consumer_protection,alipay_bind', :format => 'json', :method => 'taobao.user.get', :session => @access_token.token, :sign_method => 'md5', :timestamp => Time.now.strftime('%Y-%m-%d %H:%M:%S'), :v => '2.0' } query_param = generate_sign(query_param) res = Net::HTTP.post_form(URI.parse(url), query_param) @data ||= MultiJson.decode(res.body)['user_get_response']['user'] end |
#user_info ⇒ Object
66 67 68 69 70 71 |
# File 'lib/omniauth/strategies/oauth2/taobao.rb', line 66 def user_info { 'name' => user_data['nick'], 'email' => (user_data['email'] if user_data['email']), } end |