Class: OmniAuth::Strategies::Qzone

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/oauth/qzone.rb

Overview

Authenticate to qzone (QQ) via OAuth and retrieve basic user information.

Usage:

use OmniAuth::Strategies::Qzone, 'consumerkey', 'consumersecret'

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#consumer, #request_phase, #unique_id

Constructor Details

#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Qzone

Initialize the middleware



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/omniauth/strategies/oauth/qzone.rb', line 16

def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
  client_options = {
    :access_token_path => '/oauth/qzoneoauth_access_token',
    :authorize_path => '/oauth/qzoneoauth_authorize',
    :http_method => :get,
    :request_token_path => '/oauth/qzoneoauth_request_token',
    :scheme => :query_string,
    :site => 'http://openapi.qzone.qq.com',
  }
  options[:authorize_params] = {:oauth_consumer_key => consumer_key}
  super(app, :qzone, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/omniauth/strategies/oauth/qzone.rb', line 40

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

#callback_phaseObject



35
36
37
38
# File 'lib/omniauth/strategies/oauth/qzone.rb', line 35

def callback_phase
  session['oauth'][name.to_s]['callback_confirmed'] = true
  super
end

#consumer_optionsObject

HACK qzone is using a none-standard parameter oauth_overicode



30
31
32
33
# File 'lib/omniauth/strategies/oauth/qzone.rb', line 30

def consumer_options
  @consumer_options[:access_token_path] = '/oauth/qzoneoauth_access_token?oauth_vericode=' + request['oauth_vericode'] if request['oauth_vericode']
  @consumer_options
end

#user_hashObject



67
68
69
# File 'lib/omniauth/strategies/oauth/qzone.rb', line 67

def user_hash
  @user_hash ||= MultiJson.decode(@access_token.get("/user/get_user_info?format=json&openid=#{@access_token.params[:openid]}").body)
end

#user_infoObject



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/omniauth/strategies/oauth/qzone.rb', line 53

def 
  user_hash = self.user_hash
  {
    'uid' => @access_token.params[:openid],
    'nickname' => user_hash['nickname'],
    'name' =>  user_hash['nickname'],
    'image' => user_hash['figureurl'],
    'urls' => {
      'figureurl_1' => user_hash['figureurl_1'],
      'figureurl_2' => user_hash['figureurl_2'],
    },
  }
end