omniauth_china 0.0.1a

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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in omniauth_china.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -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
@@ -0,0 +1,3 @@
1
+ module OmniauthChina
2
+ VERSION = "0.0.1a"
3
+ end
@@ -0,0 +1 @@
1
+ require 'omniauth_china/oauth_china'
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "omniauth_china/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "omniauth_china"
7
+ s.version = OmniauthChina::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Qi He"]
10
+ s.email = ["qihe229@gmail.com"]
11
+ s.homepage = "http://rubygems.org/gems/omniauth_china"
12
+ s.summary = %q{OmniAuth extention: omniauth for china}
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
+
15
+ s.rubyforge_project = "omniauth_china"
16
+
17
+ s.add_dependency 'omniauth'
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: omniauth_china
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1a
9
+ version: 0.0.1a
10
+ platform: ruby
11
+ authors:
12
+ - Qi He
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-03-26 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: omniauth
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ description: This is an extention of OmniAuth, it addes Open ID providers in China such as Douban, Sina, Sohu, 163, etc.
34
+ email:
35
+ - qihe229@gmail.com
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Rakefile
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
52
+ - lib/omniauth_china/version.rb
53
+ - omniauth_china.gemspec
54
+ has_rdoc: true
55
+ homepage: http://rubygems.org/gems/omniauth_china
56
+ licenses: []
57
+
58
+ post_install_message:
59
+ rdoc_options: []
60
+
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
70
+ version: "0"
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">"
75
+ - !ruby/object:Gem::Version
76
+ segments:
77
+ - 1
78
+ - 3
79
+ - 1
80
+ version: 1.3.1
81
+ requirements: []
82
+
83
+ rubyforge_project: omniauth_china
84
+ rubygems_version: 1.3.7
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: "OmniAuth extention: omniauth for china"
88
+ test_files: []
89
+