Class: OmniAuth::Strategies::T163

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

Overview

Authenticate to T163 via OAuth and retrieve basic user information.

Usage:

use OmniAuth::Strategies::T163, 'APIKey', 'APIKeySecret'

Instance Attribute Summary

Attributes inherited from OAuth

#consumer_key, #consumer_options, #consumer_secret, #name

Instance Method Summary collapse

Methods inherited from OAuth

#callback_phase, #consumer, #request_phase, #unique_id

Constructor Details

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

Returns a new instance of T163.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/omniauth/strategies/oauth/t163.rb', line 13

def initialize(app, consumer_key=nil, consumer_secret=nil, options={}, &block)
  @api_key = consumer_key
  client_options = {
    :access_token_path => '/oauth/access_token',
    :authorize_path => '/oauth/authenticate',
    :realm => 'OmniAuth',
    :request_token_path => '/oauth/request_token',
    :site => 'http://api.t.163.com',
  }
  super(app, :t163, consumer_key, consumer_secret, client_options, options, &block)
end

Instance Method Details

#auth_hashObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/omniauth/strategies/oauth/t163.rb', line 25

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

#user_hashObject



52
53
54
# File 'lib/omniauth/strategies/oauth/t163.rb', line 52

def user_hash
  @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.163.com/account/verify_credentials.json").body)
end

#user_infoObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/omniauth/strategies/oauth/t163.rb', line 37

def 
  user_hash = self.user_hash
  {
    'username' => user_hash['name'],
    'name' => user_hash['realName'],
    'location' => user_hash['location'],
    'image' => user_hash['profile_image_url'],
    'description' => user_hash['description'],
    'email' => user_hash['email'],
    'urls' => {
      'T163' => 'http://t.163.com',
    },
  }
end