Class: OmniAuth::Strategies::Qzone
- 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
- #auth_hash ⇒ Object
- #callback_phase ⇒ Object
-
#consumer_options ⇒ Object
HACK qzone is using a none-standard parameter oauth_overicode.
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Qzone
constructor
Initialize the middleware.
- #user_hash ⇒ Object
- #user_info ⇒ Object
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, ={}, &block) = { :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', } [:authorize_params] = {:oauth_consumer_key => consumer_key} super(app, :qzone, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
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 = user_info OmniAuth::Utils.deep_merge(super, { 'uid' => ui['uid'], 'user_info' => ui, 'extra' => { 'user_hash' => user_hash, }, } ) end |
#callback_phase ⇒ Object
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_options ⇒ Object
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[:access_token_path] = '/oauth/qzoneoauth_access_token?oauth_vericode=' + request['oauth_vericode'] if request['oauth_vericode'] @consumer_options end |
#user_hash ⇒ Object
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_info ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/omniauth/strategies/oauth/qzone.rb', line 53 def user_info 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 |