Class: OmniAuth::Strategies::Tsohu
- Inherits:
-
OAuth
- Object
- OAuth
- OmniAuth::Strategies::Tsohu
- Defined in:
- lib/omniauth_china/strategies/tsohu.rb
Overview
Authenticate to Tsohu via OAuth and retrieve basic user information.
Usage:
use OmniAuth::Strategies::Tsohu, 'APIKey', 'APIKeySecret'
Instance Method Summary collapse
- #auth_hash ⇒ Object
-
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tsohu
constructor
A new instance of Tsohu.
- #user_hash ⇒ Object
- #user_info ⇒ Object
Constructor Details
#initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block) ⇒ Tsohu
Returns a new instance of Tsohu.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/omniauth_china/strategies/tsohu.rb', line 16 def initialize(app, consumer_key = nil, consumer_secret = nil, = {}, &block) @api_key = consumer_key = { :site => 'http://api.t.sohu.com', :request_token_path => '/oauth/request_token', :access_token_path => '/oauth/access_token', :authorize_path => '/oauth/authorize', :scheme => :header, } super(app, :tsohu, consumer_key, consumer_secret, , , &block) end |
Instance Method Details
#auth_hash ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/omniauth_china/strategies/tsohu.rb', line 30 def auth_hash OmniAuth::Utils.deep_merge(super, { 'uid' => user_hash['id'], 'user_info' => user_info, 'extra' => {'user_hash' => user_hash} }) end |
#user_hash ⇒ Object
52 53 54 |
# File 'lib/omniauth_china/strategies/tsohu.rb', line 52 def user_hash @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.sohu.com/account/verify_credentials.json").body) end |
#user_info ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/omniauth_china/strategies/tsohu.rb', line 38 def user_info user_hash = self.user_hash { 'username' => user_hash['screen_name'], 'name' => user_hash['name'], 'location' => user_hash['location'], 'image' => user_hash['profile_image_url'], 'description' => user_hash['description'], 'urls' => { 'Tsohu' => user_hash['url'] } } end |