Class: OmniAuth::Strategies::Tqq
- Defined in:
- lib/omniauth/strategies/oauth/tqq.rb
Overview
Authenticate to Tqq via OAuth and retrieve basic user information.
Usage: use OmniAuth::Strategies::Tqq, 'APIKey', 'APIKeySecret'
Instance Attribute Summary
Attributes inherited from OAuth
#consumer_key, #consumer_options, #consumer_secret, #name
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tqq
constructor
A new instance of Tqq.
- #nonce ⇒ Object
- #user_hash ⇒ Object
- #user_info ⇒ Object
Methods inherited from OAuth
#callback_phase, #consumer, #request_phase, #unique_id
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tqq
Returns a new instance of Tqq.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/omniauth/strategies/oauth/tqq.rb', line 13 def initialize(app, consumer_key=nil, consumer_secret=nil, ={}, &block) @api_key = consumer_key = { :access_token_path => '/cgi-bin/access_token', :authorize_path => '/cgi-bin/authorize', :http_method => :get, :nonce => nonce, :realm => 'OmniAuth', :request_token_path => '/cgi-bin/request_token', :scheme => :query_string, :site => 'https://open.t.qq.com', } super(app, :tqq, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/omniauth/strategies/oauth/tqq.rb', line 32 def auth_hash OmniAuth::Utils.deep_merge( super, { 'uid' => user_hash['data']['uid'], 'user_info' => user_info, 'extra' => { 'user_hash' => user_hash, }, } ) end |
#nonce ⇒ Object
28 29 30 |
# File 'lib/omniauth/strategies/oauth/tqq.rb', line 28 def nonce Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')[0, 32] end |
#user_hash ⇒ Object
58 59 60 |
# File 'lib/omniauth/strategies/oauth/tqq.rb', line 58 def user_hash @user_hash ||= MultiJson.decode(@access_token.get('http://open.t.qq.com/api/user/info?format=json').body) end |
#user_info ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/omniauth/strategies/oauth/tqq.rb', line 44 def user_info user_hash = self.user_hash { 'username' => user_hash['data']['name'], 'name' => user_hash['data']['nick'], 'location' => user_hash['data']['location'], 'image' => user_hash['data']['head'], 'description' => user_hash['description'], 'urls' => { 'Tqq' => 't.qq.com', }, } end |