Class: OmniAuth::Strategies::Tqq
- Inherits:
-
OAuth
- Object
- OAuth
- OmniAuth::Strategies::Tqq
- Defined in:
- lib/omniauth_china/strategies/tqq.rb
Overview
Authenticate to Tqq via OAuth and retrieve basic user information.
Usage:
use OmniAuth::Strategies::Tqq, 'APIKey', 'APIKeySecret'
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
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tqq
Returns a new instance of Tqq.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/omniauth_china/strategies/tqq.rb', line 16 def initialize(app, consumer_key = nil, consumer_secret = nil, = {}, &block) @api_key = consumer_key = { :site => 'https://open.t.qq.com', :request_token_path => '/cgi-bin/request_token', :access_token_path => '/cgi-bin/access_token', :authorize_path => '/cgi-bin/authorize', :realm => 'OmniAuth', :scheme => :query_string, :nonce => nonce, :http_method => :get, } super(app, :tqq, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/omniauth_china/strategies/tqq.rb', line 37 def auth_hash # NOTE: Tencent not give uid current, use username instead. OmniAuth::Utils.deep_merge(super, { 'uid' => user_hash["data"]['name'], 'user_info' => user_info, 'extra' => {'user_hash' => user_hash} }) end |
#nonce ⇒ Object
33 34 35 |
# File 'lib/omniauth_china/strategies/tqq.rb', line 33 def nonce Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')[0, 32] end |
#user_hash ⇒ Object
60 61 62 |
# File 'lib/omniauth_china/strategies/tqq.rb', line 60 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
46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/omniauth_china/strategies/tqq.rb', line 46 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['data']['introduction'], 'urls' => { 'Tqq' => 't.qq.com' } } end |