omniauth_china 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,10 @@
1
+ arequire 'omniauth/core'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ autoload :Douban, 'omniauth_china/strategies/douban'
6
+ autoload :Tsina, 'omniauth_china/strategies/tsina'
7
+ autoload :T163, 'omniauth_china/strategies/t163'
8
+ autoload :Tsohu, 'omniauth_china/strategies/tsohu'
9
+ end
10
+ end
@@ -0,0 +1,60 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Douban via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::Douban, 'APIKey', 'APIKeySecret'
13
+ #
14
+ class Douban < OmniAuth::Strategies::OAuth
15
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
16
+ # Although in OAuth spec the :realm parameter is optional,
17
+ # it is required for Douban.
18
+ client_options = {
19
+ :site => 'http://www.douban.com',
20
+ :request_token_path => '/service/auth/request_token',
21
+ :access_token_path => '/service/auth/access_token',
22
+ :authorize_path => '/service/auth/authorize',
23
+ :realm => 'OmniAuth'
24
+ }
25
+
26
+ super(app, :douban, consumer_key, consumer_secret, client_options, options, &block)
27
+ end
28
+
29
+ def auth_hash
30
+ OmniAuth::Utils.deep_merge(super, {
31
+ 'uid' => @access_token.params[:douban_user_id],
32
+ 'user_info' => user_info,
33
+ 'extra' => {'user_hash' => user_hash}
34
+ })
35
+ end
36
+
37
+ def user_info
38
+ user_hash = self.user_hash
39
+
40
+ location = user_hash['location'] ? user_hash['location']['$t'] : nil
41
+ image = user_hash['link'].find {|l| l['@rel'] == 'icon' }['@href']
42
+ douban_url = user_hash['link'].find {|l| l['@rel'] == 'alternate' }['@href']
43
+ {
44
+ 'username' => user_hash['db:uid']['$t'],
45
+ 'name' => user_hash['title']['$t'],
46
+ 'location' => location,
47
+ 'image' => image,
48
+ 'description' => user_hash['content']['$t'],
49
+ 'urls' => {
50
+ 'Douban' => douban_url
51
+ }
52
+ }
53
+ end
54
+
55
+ def user_hash
56
+ @user_hash ||= MultiJson.decode(@access_token.get('http://api.douban.com/people/%40me?alt=json').body)
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,57 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to T163 via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::T163, 'APIKey', 'APIKeySecret'
13
+ #
14
+ class T163 < OmniAuth::Strategies::OAuth
15
+
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ @api_key = consumer_key
18
+
19
+ client_options = {
20
+ :site => 'http://api.t.163.com',
21
+ :request_token_path => '/oauth/request_token',
22
+ :access_token_path => '/oauth/access_token',
23
+ :authorize_path => '/oauth/authenticate',
24
+ :realm => 'OmniAuth'
25
+ }
26
+
27
+ super(app, :t163, consumer_key, consumer_secret, client_options, options, &block)
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super, {
32
+ 'uid' => user_hash['screen_name'],
33
+ 'user_info' => user_info,
34
+ 'extra' => {'user_hash' => user_hash}
35
+ })
36
+ end
37
+
38
+ def user_info
39
+ user_hash = self.user_hash
40
+ {
41
+ 'username' => user_hash['name'],
42
+ 'name' => user_hash['realName'],
43
+ 'location' => user_hash['location'],
44
+ 'image' => user_hash['profile_image_url'],
45
+ 'description' => user_hash['description'],
46
+ 'urls' => {
47
+ 'T163' => 'http://t.163.com'
48
+ }
49
+ }
50
+ end
51
+
52
+ def user_hash
53
+ @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.163.com/account/verify_credentials.json").body)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,61 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to TSina via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::TSina, 'APIKey', 'APIKeySecret'
13
+ #
14
+ class Tsina < OmniAuth::Strategies::OAuth
15
+
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ @api_key = consumer_key
18
+
19
+ client_options = {
20
+ :site => 'http://api.t.sina.com.cn',
21
+ :request_token_path => '/oauth/request_token',
22
+ :access_token_path => '/oauth/access_token',
23
+ :authorize_path => '/oauth/authorize',
24
+ :realm => 'OmniAuth'
25
+ }
26
+
27
+ super(app, :tsina, consumer_key, consumer_secret, client_options, options, &block)
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super, {
32
+ 'uid' => @access_token.params[:user_id],
33
+ 'user_info' => user_info,
34
+ 'extra' => {'user_hash' => user_hash}
35
+ })
36
+ end
37
+
38
+ def user_info
39
+ user_hash = self.user_hash
40
+ {
41
+ 'username' => user_hash['screen_name'],
42
+ 'name' => user_hash['name'],
43
+ 'location' => user_hash['location'],
44
+ 'image' => user_hash['profile_image_url'],
45
+ 'description' => user_hash['description'],
46
+ 'urls' => {
47
+ 'Tsina' => user_hash['url']
48
+ }
49
+ }
50
+ end
51
+
52
+ def user_hash
53
+ # http://api.t.sina.com.cn/users/show/:id.json?source=appkey
54
+ # @access_token.params[:user_id] is the UID
55
+ # @api_key is the appkey
56
+ uid = @access_token.params[:user_id]
57
+ @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.sina.com.cn/users/show/#{uid}.json?source=#{@api_key}").body)
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,57 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Tsohu via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::Tsohu, 'APIKey', 'APIKeySecret'
13
+ #
14
+ class Tsohu < OmniAuth::Strategies::OAuth
15
+
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ @api_key = consumer_key
18
+
19
+ client_options = {
20
+ :site => 'http://api.t.sohu.com',
21
+ :request_token_path => '/oauth/request_token',
22
+ :access_token_path => '/oauth/access_token',
23
+ :authorize_path => '/oauth/authorize',
24
+ :realm => 'OmniAuth'
25
+ }
26
+
27
+ super(app, :tsohu, consumer_key, consumer_secret, client_options, options, &block)
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super, {
32
+ 'uid' => user_hash['id'],
33
+ 'user_info' => user_info,
34
+ 'extra' => {'user_hash' => user_hash}
35
+ })
36
+ end
37
+
38
+ def user_info
39
+ user_hash = self.user_hash
40
+ {
41
+ 'username' => user_hash['screen_name'],
42
+ 'name' => user_hash['name'],
43
+ 'location' => user_hash['location'],
44
+ 'image' => user_hash['profile_image_url'],
45
+ 'description' => user_hash['description'],
46
+ 'urls' => {
47
+ 'Tsohu' => user_hash['url']
48
+ }
49
+ }
50
+ end
51
+
52
+ def user_hash
53
+ @user_hash ||= MultiJson.decode(@access_token.get("http://api.t.sohu.com/account/verify_credentials.json").body)
54
+ end
55
+ end
56
+ end
57
+ end
@@ -1,3 +1,3 @@
1
1
  module OmniauthChina
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
10
10
  s.email = ["qihe229@gmail.com"]
11
11
  s.homepage = "http://rubygems.org/gems/omniauth_china"
12
12
  s.summary = %q{OmniAuth extention: omniauth for china}
13
- s.description = %q{This is an extention of OmniAuth, it ades Open ID providers in China such as Douban, Sina, Sohu, 163, etc.}
13
+ s.description = %q{This is an extention of OmniAuth, it addes Open ID providers in China such as Douban, Sina, Sohu, 163, etc.}
14
14
 
15
15
  s.rubyforge_project = "omniauth_china"
16
16
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Qi He
@@ -30,7 +30,7 @@ dependencies:
30
30
  version: "0"
31
31
  type: :runtime
32
32
  version_requirements: *id001
33
- description: This is an extention of OmniAuth, it ades Open ID providers in China such as Douban, Sina, Sohu, 163, etc.
33
+ description: This is an extention of OmniAuth, it addes Open ID providers in China such as Douban, Sina, Sohu, 163, etc.
34
34
  email:
35
35
  - qihe229@gmail.com
36
36
  executables: []
@@ -44,6 +44,11 @@ files:
44
44
  - Gemfile
45
45
  - Rakefile
46
46
  - lib/omniauth_china.rb
47
+ - lib/omniauth_china/oauth_china.rb
48
+ - lib/omniauth_china/strategies/douban.rb
49
+ - lib/omniauth_china/strategies/t163.rb
50
+ - lib/omniauth_china/strategies/tsina.rb
51
+ - lib/omniauth_china/strategies/tsohu.rb
47
52
  - lib/omniauth_china/version.rb
48
53
  - omniauth_china.gemspec
49
54
  has_rdoc: true