Class: OmniAuth::Strategies::Tqq

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/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

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.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/omniauth/strategies/tqq.rb', line 16

def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
  @api_key = consumer_key

  client_options = {
    :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, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



37
38
39
40
41
42
43
# File 'lib/omniauth/strategies/tqq.rb', line 37

def auth_hash
  OmniAuth::Utils.deep_merge(super, {
    'uid' => user_hash["data"]['uid'],
    'user_info' => ,
    'extra' => {'user_hash' => user_hash}
  })
end

#nonceObject



33
34
35
# File 'lib/omniauth/strategies/tqq.rb', line 33

def nonce
  Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')[0, 32]
end

#user_hashObject



59
60
61
# File 'lib/omniauth/strategies/tqq.rb', line 59

def user_hash
  @user_hash ||= MultiJson.decode(@access_token.get("http://open.t.qq.com/api/user/info?format=json").body)
end

#user_infoObject



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/omniauth/strategies/tqq.rb', line 45

def 
  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