Class: OmniAuth::Strategies::Qzone

Inherits:
OAuth
  • Object
show all
Defined in:
lib/omniauth/strategies/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
28
# File 'lib/omniauth/strategies/qzone.rb', line 16

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

  options[:authorize_params] = {:oauth_consumer_key => consumer_key}
  super(app, :qzone, consumer_key, consumer_secret, client_options, options)
end

Instance Method Details

#auth_hashObject



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

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

#callback_phaseObject



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

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



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

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



64
65
66
# File 'lib/omniauth/strategies/qzone.rb', line 64

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



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/omniauth/strategies/qzone.rb', line 50

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