oa-oauth 0.1.6 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- data/.gemtest +0 -0
- data/.rspec +3 -0
- data/.yardopts +4 -0
- data/{LICENSE.rdoc → LICENSE} +2 -2
- data/README.rdoc +1 -1
- data/Rakefile +6 -0
- data/autotest/discover.rb +1 -0
- data/lib/oa-oauth.rb +1 -0
- data/lib/omniauth/oauth.rb +39 -7
- data/lib/omniauth/strategies/bitly.rb +46 -0
- data/lib/omniauth/strategies/dailymile.rb +64 -0
- data/lib/omniauth/strategies/doit.rb +60 -0
- data/lib/omniauth/strategies/dopplr.rb +38 -7
- data/lib/omniauth/strategies/douban.rb +60 -0
- data/lib/omniauth/strategies/evernote.rb +54 -0
- data/lib/omniauth/strategies/facebook.rb +29 -11
- data/lib/omniauth/strategies/foursquare.rb +50 -27
- data/lib/omniauth/strategies/github.rb +15 -12
- data/lib/omniauth/strategies/goodreads.rb +44 -0
- data/lib/omniauth/strategies/google.rb +80 -0
- data/lib/omniauth/strategies/gowalla.rb +13 -10
- data/lib/omniauth/strategies/hyves.rb +67 -0
- data/lib/omniauth/strategies/identica.rb +4 -4
- data/lib/omniauth/strategies/instagram.rb +56 -0
- data/lib/omniauth/strategies/instapaper.rb +40 -0
- data/lib/omniauth/strategies/linked_in.rb +24 -15
- data/lib/omniauth/strategies/meetup.rb +40 -7
- data/lib/omniauth/strategies/miso.rb +41 -0
- data/lib/omniauth/strategies/mixi.rb +59 -0
- data/lib/omniauth/strategies/netflix.rb +65 -0
- data/lib/omniauth/strategies/oauth.rb +51 -13
- data/lib/omniauth/strategies/oauth2.rb +48 -23
- data/lib/omniauth/strategies/qzone.rb +69 -0
- data/lib/omniauth/strategies/rdio.rb +45 -0
- data/lib/omniauth/strategies/renren.rb +87 -0
- data/lib/omniauth/strategies/salesforce.rb +44 -0
- data/lib/omniauth/strategies/smug_mug.rb +42 -0
- data/lib/omniauth/strategies/sound_cloud.rb +9 -9
- data/lib/omniauth/strategies/t163.rb +57 -0
- data/lib/omniauth/strategies/teambox.rb +49 -0
- data/lib/omniauth/strategies/thirty_seven_signals.rb +11 -8
- data/lib/omniauth/strategies/tqq.rb +64 -0
- data/lib/omniauth/strategies/trade_me.rb +45 -0
- data/lib/omniauth/strategies/trip_it.rb +3 -16
- data/lib/omniauth/strategies/tsina.rb +79 -0
- data/lib/omniauth/strategies/tsohu.rb +57 -0
- data/lib/omniauth/strategies/tumblr.rb +60 -0
- data/lib/omniauth/strategies/twitter.rb +21 -11
- data/lib/omniauth/strategies/type_pad.rb +76 -0
- data/lib/omniauth/strategies/vimeo.rb +54 -0
- data/lib/omniauth/strategies/vkontakte.rb +84 -0
- data/lib/omniauth/strategies/xauth.rb +67 -0
- data/lib/omniauth/strategies/yahoo.rb +55 -0
- data/lib/omniauth/strategies/yammer.rb +43 -0
- data/lib/omniauth/strategies/you_tube.rb +73 -0
- data/lib/omniauth/version.rb +19 -0
- data/oa-oauth.gemspec +33 -0
- data/spec/fixtures/basecamp_200.xml +24 -0
- data/spec/fixtures/campfire_200.json +10 -0
- data/spec/omniauth/strategies/bitly_spec.rb +5 -0
- data/spec/omniauth/strategies/dailymile_spec.rb +5 -0
- data/spec/omniauth/strategies/doit_spec.rb +5 -0
- data/spec/omniauth/strategies/dopplr_spec.rb +5 -0
- data/spec/omniauth/strategies/douban_spec.rb +5 -0
- data/spec/omniauth/strategies/evernote_spec.rb +5 -0
- data/spec/omniauth/strategies/facebook_spec.rb +5 -0
- data/spec/omniauth/strategies/foursquare_spec.rb +18 -0
- data/spec/omniauth/strategies/github_spec.rb +5 -0
- data/spec/omniauth/strategies/goodreads_spec.rb +6 -0
- data/spec/omniauth/strategies/google_spec.rb +5 -0
- data/spec/omniauth/strategies/gowalla_spec.rb +5 -0
- data/spec/omniauth/strategies/hyves_spec.rb +5 -0
- data/spec/omniauth/strategies/identica_spec.rb +5 -0
- data/spec/omniauth/strategies/linked_in_spec.rb +5 -0
- data/spec/omniauth/strategies/meetup_spec.rb +14 -0
- data/spec/omniauth/strategies/miso_spec.rb +5 -0
- data/spec/omniauth/strategies/netflix_spec.rb +5 -0
- data/spec/omniauth/strategies/oauth2_spec.rb +0 -0
- data/spec/omniauth/strategies/oauth_spec.rb +77 -0
- data/spec/omniauth/strategies/rdio_spec.rb +5 -0
- data/spec/omniauth/strategies/salesforce_spec.rb +5 -0
- data/spec/omniauth/strategies/smug_mug_spec.rb +5 -0
- data/spec/omniauth/strategies/sound_cloud_spec.rb +5 -0
- data/spec/omniauth/strategies/t163_spec.rb +5 -0
- data/spec/omniauth/strategies/teambox_spec.rb +5 -0
- data/spec/omniauth/strategies/thirty_seven_signals_spec.rb +5 -0
- data/spec/omniauth/strategies/trade_me_spec.rb +5 -0
- data/spec/omniauth/strategies/trip_it_spec.rb +5 -0
- data/spec/omniauth/strategies/tsina_spec.rb +5 -0
- data/spec/omniauth/strategies/tumblr_spec.rb +5 -0
- data/spec/omniauth/strategies/twitter_spec.rb +20 -0
- data/spec/omniauth/strategies/type_pad_spec.rb +5 -0
- data/spec/omniauth/strategies/vimeo_spec.rb +5 -0
- data/spec/omniauth/strategies/vkontakte_spec.rb +5 -0
- data/spec/omniauth/strategies/yahoo_spec.rb +5 -0
- data/spec/omniauth/strategies/yammer_spec.rb +5 -0
- data/spec/omniauth/strategies/you_tube_spec.rb +5 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/shared_examples.rb +29 -0
- metadata +231 -127
- data/CHANGELOG.rdoc +0 -5
@@ -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,49 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Teambox < OAuth2
|
7
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
8
|
+
client_options = {
|
9
|
+
:site => "https://teambox.com/",
|
10
|
+
:authorize_path => "/oauth/authorize",
|
11
|
+
:access_token_path => "/oauth/token"
|
12
|
+
}
|
13
|
+
super(app, :teambox, client_id, client_secret, client_options, options, &block)
|
14
|
+
end
|
15
|
+
def request_phase
|
16
|
+
options[:scope] ||= "offline_access"
|
17
|
+
options[:response_type] ||= 'code'
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def callback_phase
|
22
|
+
options[:grant_type] ||= 'authorization_code'
|
23
|
+
super
|
24
|
+
end
|
25
|
+
|
26
|
+
def user_data
|
27
|
+
@data ||= MultiJson.decode(@access_token.get("/api/1/account"))
|
28
|
+
end
|
29
|
+
|
30
|
+
def user_info
|
31
|
+
{
|
32
|
+
'nickname' => user_data['username'],
|
33
|
+
'name' => user_data['first_name'],
|
34
|
+
'image' => user_data['avatar_url'],
|
35
|
+
'urls' => {}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
def auth_hash
|
40
|
+
OmniAuth::Utils.deep_merge(super, {
|
41
|
+
'uid' => user_data['id'],
|
42
|
+
'user_info' => user_info,
|
43
|
+
'extra' => {'user_hash' => user_data}
|
44
|
+
})
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -4,17 +4,20 @@ require 'multi_json'
|
|
4
4
|
module OmniAuth
|
5
5
|
module Strategies
|
6
6
|
class ThirtySevenSignals < OAuth2
|
7
|
-
def initialize(app,
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
8
|
+
client_options = {
|
9
|
+
:site => 'https://launchpad.37signals.com/',
|
10
|
+
:authorize_path => '/authorization/new',
|
11
|
+
:access_token_path => '/authorization/token'
|
12
|
+
}
|
13
|
+
|
14
|
+
super(app, :thirty_seven_signals, client_id, client_secret, client_options, options, &block)
|
12
15
|
end
|
13
|
-
|
16
|
+
|
14
17
|
def user_data
|
15
18
|
@data ||= MultiJson.decode(@access_token.get('/authorization.json'))
|
16
19
|
end
|
17
|
-
|
20
|
+
|
18
21
|
def user_info
|
19
22
|
{
|
20
23
|
'email' => user_data['identity']['email_address'],
|
@@ -23,7 +26,7 @@ module OmniAuth
|
|
23
26
|
'name' => [user_data['identity']['first_name'], user_data['identity']['last_name']].join(' ').strip
|
24
27
|
}
|
25
28
|
end
|
26
|
-
|
29
|
+
|
27
30
|
def auth_hash
|
28
31
|
OmniAuth::Utils.deep_merge(super, {
|
29
32
|
'uid' => user_data['identity']['id'],
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Tqq via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Tqq, 'APIKey', 'APIKeySecret'
|
13
|
+
#
|
14
|
+
class Tqq < 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 => 'https://open.t.qq.com',
|
21
|
+
:request_token_path => '/cgi-bin/request_token',
|
22
|
+
:access_token_path => '/cgi-bin/access_token',
|
23
|
+
:authorize_path => '/cgi-bin/authorize',
|
24
|
+
:realm => 'OmniAuth',
|
25
|
+
:scheme => :query_string,
|
26
|
+
:nonce => nonce,
|
27
|
+
:http_method => :get,
|
28
|
+
}
|
29
|
+
|
30
|
+
super(app, :tqq, consumer_key, consumer_secret, client_options, options, &block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def nonce
|
34
|
+
Base64.encode64(OpenSSL::Random.random_bytes(32)).gsub(/\W/, '')[0, 32]
|
35
|
+
end
|
36
|
+
|
37
|
+
def auth_hash
|
38
|
+
OmniAuth::Utils.deep_merge(super, {
|
39
|
+
'uid' => user_hash["data"]['uid'],
|
40
|
+
'user_info' => user_info,
|
41
|
+
'extra' => {'user_hash' => user_hash}
|
42
|
+
})
|
43
|
+
end
|
44
|
+
|
45
|
+
def user_info
|
46
|
+
user_hash = self.user_hash
|
47
|
+
{
|
48
|
+
'username' => user_hash["data"]['name'],
|
49
|
+
'name' => user_hash["data"]['nick'],
|
50
|
+
'location' => user_hash["data"]['location'],
|
51
|
+
'image' => user_hash["data"]['head'],
|
52
|
+
'description' => user_hash['description'],
|
53
|
+
'urls' => {
|
54
|
+
'Tqq' => 't.qq.com'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def user_hash
|
60
|
+
@user_hash ||= MultiJson.decode(@access_token.get("http://open.t.qq.com/api/user/info?format=json").body)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to TradeMe via OAuth and retrieve basic user information.
|
8
|
+
# Usage:
|
9
|
+
# use OmniAuth::Strategies::TradeMe, 'consumerkey', 'consumersecret'
|
10
|
+
#
|
11
|
+
class TradeMe < OmniAuth::Strategies::OAuth
|
12
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
13
|
+
super(app, :trademe, consumer_key, consumer_secret,
|
14
|
+
{:site => 'https://secure.trademe.co.nz',
|
15
|
+
:request_token_path => "/Oauth/RequestToken",
|
16
|
+
:access_token_path => "/Oauth/AccessToken",
|
17
|
+
:authorize_path => "/Oauth/Authorize",
|
18
|
+
}, options, &block)
|
19
|
+
end
|
20
|
+
|
21
|
+
def auth_hash
|
22
|
+
OmniAuth::Utils.deep_merge(super, {
|
23
|
+
'uid' => user_hash['MemberId'],
|
24
|
+
'user_info' => user_info,
|
25
|
+
'extra' => { 'user_hash' => user_hash },
|
26
|
+
})
|
27
|
+
end
|
28
|
+
|
29
|
+
# user info according to schema
|
30
|
+
def user_info
|
31
|
+
{
|
32
|
+
'nickname' => user_hash['Nickname'],
|
33
|
+
'first_name' => user_hash['FirstName'],
|
34
|
+
'last_name' => user_hash['LastName'],
|
35
|
+
'name' => [user_hash['FirstName'],user_hash['LastName']].reject{ |n| n.nil? || n.empty? }.join(' '),
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
39
|
+
# info as supplied by TradeMe user summary
|
40
|
+
def user_hash
|
41
|
+
@user_hash ||= MultiJson.decode(@access_token.get('https://api.trademe.co.nz/v1/MyTradeMe/Summary.json').body)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -10,25 +10,12 @@ module OmniAuth
|
|
10
10
|
# use OmniAuth::Strategies::TripIt, 'consumerkey', 'consumersecret'
|
11
11
|
#
|
12
12
|
class TripIt < OmniAuth::Strategies::OAuth
|
13
|
-
def initialize(app, consumer_key, consumer_secret)
|
13
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
14
14
|
super(app, :tripit, consumer_key, consumer_secret,
|
15
|
-
:site => 'https://api.tripit.com',
|
15
|
+
{:site => 'https://api.tripit.com',
|
16
16
|
:request_token_path => "/oauth/request_token",
|
17
17
|
:access_token_path => "/oauth/access_token",
|
18
|
-
:authorize_url => "https://www.tripit.com/oauth/authorize")
|
19
|
-
end
|
20
|
-
|
21
|
-
def request_phase
|
22
|
-
request_token = consumer.get_request_token(:oauth_callback => callback_url)
|
23
|
-
(session[:oauth]||={})[name.to_sym] = {:callback_confirmed => request_token.callback_confirmed?, :request_token => request_token.token, :request_secret => request_token.secret}
|
24
|
-
r = Rack::Response.new
|
25
|
-
# For some reason, TripIt NEEDS the &oauth_callback query param or the user receives an error.
|
26
|
-
r.redirect request_token.authorize_url + "&oauth_callback=" + urlencode(callback_url)
|
27
|
-
r.finish
|
28
|
-
end
|
29
|
-
|
30
|
-
def urlencode(str)
|
31
|
-
str.gsub(/[^a-zA-Z0-9_\.\-]/n) { sprintf('%%%02x', $&[0].ord) }
|
18
|
+
:authorize_url => "https://www.tripit.com/oauth/authorize"}, options, &block)
|
32
19
|
end
|
33
20
|
end
|
34
21
|
end
|
@@ -0,0 +1,79 @@
|
|
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
|
+
# MonkeyPatch session['oauth']['tsina']['callback_confirmed'] to true
|
53
|
+
def request_phase
|
54
|
+
request_token = consumer.get_request_token(:oauth_callback => callback_url)
|
55
|
+
session['oauth'] ||= {}
|
56
|
+
session['oauth'][name.to_s] = {'callback_confirmed' => true, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
57
|
+
r = Rack::Response.new
|
58
|
+
|
59
|
+
if request_token.callback_confirmed?
|
60
|
+
r.redirect(request_token.authorize_url)
|
61
|
+
else
|
62
|
+
r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
|
63
|
+
end
|
64
|
+
|
65
|
+
r.finish
|
66
|
+
rescue ::Timeout::Error => e
|
67
|
+
fail!(:timeout, e)
|
68
|
+
end
|
69
|
+
|
70
|
+
def user_hash
|
71
|
+
# http://api.t.sina.com.cn/users/show/:id.json?source=appkey
|
72
|
+
# @access_token.params[:user_id] is the UID
|
73
|
+
# @api_key is the appkey
|
74
|
+
uid = @access_token.params[:user_id]
|
75
|
+
@user_hash ||= MultiJson.decode(@access_token.get("http://api.t.sina.com.cn/users/show/#{uid}.json?source=#{@api_key}").body)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
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
|
+
:scheme => :header,
|
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,60 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
|
3
|
+
module OmniAuth
|
4
|
+
module Strategies
|
5
|
+
#
|
6
|
+
# Authenticate to Tumblr via OAuth and retrieve basic
|
7
|
+
# user information.
|
8
|
+
#
|
9
|
+
# Usage:
|
10
|
+
#
|
11
|
+
# use OmniAuth::Strategies::Tumblr, 'consumerkey', 'consumersecret'
|
12
|
+
#
|
13
|
+
class Tumblr < OmniAuth::Strategies::OAuth
|
14
|
+
# Initialize the middleware
|
15
|
+
#
|
16
|
+
# @option options [Boolean, true] :sign_in When true, use the "Sign in with Tumblr" flow instead of the authorization flow.
|
17
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
18
|
+
client_options = {
|
19
|
+
:site => 'http://www.tumblr.com'
|
20
|
+
}
|
21
|
+
|
22
|
+
client_options[:authorize_path] = '/oauth/authorize' unless options[:sign_in] == false
|
23
|
+
super(app, :tumblr, consumer_key, consumer_secret, client_options, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def auth_hash
|
27
|
+
OmniAuth::Utils.deep_merge(super, {
|
28
|
+
'uid' => user['name'],
|
29
|
+
'user_info' => user_info,
|
30
|
+
'extra' => { 'user_hash' => user }
|
31
|
+
})
|
32
|
+
end
|
33
|
+
|
34
|
+
def user_info
|
35
|
+
{
|
36
|
+
'nickname' => user['name'],
|
37
|
+
'name' => user['title'],
|
38
|
+
'image' => user['avatar_url'],
|
39
|
+
'urls' => {
|
40
|
+
'website' => user['url'],
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
def user
|
46
|
+
tumblelogs = user_hash['tumblr']['tumblelog']
|
47
|
+
if tumblelogs.kind_of?(Array)
|
48
|
+
@user ||= tumblelogs[0]
|
49
|
+
else
|
50
|
+
@user ||= tumblelogs
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def user_hash
|
55
|
+
url = "http://www.tumblr.com/api/authenticate"
|
56
|
+
@user_hash ||= Hash.from_xml(@access_token.get(url).body)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|