Class: OmniAuth::Strategies::Qzone
- Inherits:
-
OAuth
- Object
- OAuth
- OmniAuth::Strategies::Qzone
- Defined in:
- lib/omniauth_china/strategies/qzone.rb
Overview
Authenticate to qzone (QQ) via OAuth and retrieve basic user information.
Usage:
use OmniAuth::Strategies::Qzone, 'consumerkey', 'consumersecret'
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
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_china/strategies/qzone.rb', line 16 def initialize(app, consumer_key = nil, consumer_secret = nil, = {}, &block) = { :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 } [:authorize_params] = {:oauth_consumer_key => consumer_key} super(app, :qzone, consumer_key, consumer_secret, , ) end |
Instance Method Details
#auth_hash ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/omniauth_china/strategies/qzone.rb', line 41 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
36 37 38 39 |
# File 'lib/omniauth_china/strategies/qzone.rb', line 36 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
31 32 33 34 |
# File 'lib/omniauth_china/strategies/qzone.rb', line 31 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
64 65 66 |
# File 'lib/omniauth_china/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_info ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/omniauth_china/strategies/qzone.rb', line 50 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 |