oa-oauth 0.1.6 → 0.2.5
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/.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
data/.gemtest
ADDED
|
File without changes
|
data/.rspec
ADDED
data/.yardopts
ADDED
data/{LICENSE.rdoc → LICENSE}
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright (c) 2010 Michael Bleigh
|
|
1
|
+
Copyright (c) 2010-2011 Michael Bleigh and Intridea, Inc.
|
|
2
2
|
|
|
3
3
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
4
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -16,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
16
16
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
17
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
18
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
THE SOFTWARE.
|
|
19
|
+
THE SOFTWARE.
|
data/README.rdoc
CHANGED
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Autotest.add_discovery { "rspec2" }
|
data/lib/oa-oauth.rb
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
data/lib/omniauth/oauth.rb
CHANGED
|
@@ -4,18 +4,50 @@ module OmniAuth
|
|
|
4
4
|
module Strategies
|
|
5
5
|
autoload :OAuth, 'omniauth/strategies/oauth'
|
|
6
6
|
autoload :OAuth2, 'omniauth/strategies/oauth2'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
autoload :
|
|
7
|
+
autoload :XAuth, 'omniauth/strategies/xauth'
|
|
8
|
+
|
|
9
|
+
autoload :Bitly, 'omniauth/strategies/bitly'
|
|
10
|
+
autoload :Dailymile, 'omniauth/strategies/dailymile'
|
|
11
|
+
autoload :Doit, 'omniauth/strategies/doit'
|
|
12
|
+
autoload :Dopplr, 'omniauth/strategies/dopplr'
|
|
13
|
+
autoload :Douban, 'omniauth/strategies/douban'
|
|
14
|
+
autoload :Evernote, 'omniauth/strategies/evernote'
|
|
10
15
|
autoload :Facebook, 'omniauth/strategies/facebook'
|
|
11
|
-
autoload :GitHub, 'omniauth/strategies/github'
|
|
12
|
-
autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals'
|
|
13
16
|
autoload :Foursquare, 'omniauth/strategies/foursquare'
|
|
17
|
+
autoload :GitHub, 'omniauth/strategies/github'
|
|
18
|
+
autoload :Goodreads, 'omniauth/strategies/goodreads'
|
|
19
|
+
autoload :Google, 'omniauth/strategies/google'
|
|
14
20
|
autoload :Gowalla, 'omniauth/strategies/gowalla'
|
|
21
|
+
autoload :Hyves, 'omniauth/strategies/hyves'
|
|
15
22
|
autoload :Identica, 'omniauth/strategies/identica'
|
|
16
|
-
autoload :
|
|
17
|
-
autoload :
|
|
23
|
+
autoload :Instagram, 'omniauth/strategies/instagram'
|
|
24
|
+
autoload :Instapaper, 'omniauth/strategies/instapaper'
|
|
25
|
+
autoload :LinkedIn, 'omniauth/strategies/linked_in'
|
|
18
26
|
autoload :Meetup, 'omniauth/strategies/meetup'
|
|
27
|
+
autoload :Miso, 'omniauth/strategies/miso'
|
|
28
|
+
autoload :Mixi, 'omniauth/strategies/mixi'
|
|
29
|
+
autoload :Netflix, 'omniauth/strategies/netflix'
|
|
30
|
+
autoload :Qzone, 'omniauth/strategies/qzone'
|
|
31
|
+
autoload :Rdio, 'omniauth/strategies/rdio'
|
|
32
|
+
autoload :Renren, 'omniauth/strategies/renren'
|
|
33
|
+
autoload :Salesforce, 'omniauth/strategies/salesforce'
|
|
34
|
+
autoload :SmugMug, 'omniauth/strategies/smug_mug'
|
|
19
35
|
autoload :SoundCloud, 'omniauth/strategies/sound_cloud'
|
|
36
|
+
autoload :T163, 'omniauth/strategies/t163'
|
|
37
|
+
autoload :Teambox, 'omniauth/strategies/teambox'
|
|
38
|
+
autoload :ThirtySevenSignals, 'omniauth/strategies/thirty_seven_signals'
|
|
39
|
+
autoload :Tqq, 'omniauth/strategies/tqq'
|
|
40
|
+
autoload :TradeMe, 'omniauth/strategies/trade_me'
|
|
41
|
+
autoload :TripIt, 'omniauth/strategies/trip_it'
|
|
42
|
+
autoload :Tsina, 'omniauth/strategies/tsina'
|
|
43
|
+
autoload :Tsohu, 'omniauth/strategies/tsohu'
|
|
44
|
+
autoload :Tumblr, 'omniauth/strategies/tumblr'
|
|
45
|
+
autoload :Twitter, 'omniauth/strategies/twitter'
|
|
46
|
+
autoload :TypePad, 'omniauth/strategies/type_pad'
|
|
47
|
+
autoload :Vimeo, 'omniauth/strategies/vimeo'
|
|
48
|
+
autoload :Vkontakte, 'omniauth/strategies/vkontakte'
|
|
49
|
+
autoload :Yahoo, 'omniauth/strategies/yahoo'
|
|
50
|
+
autoload :Yammer, 'omniauth/strategies/yammer'
|
|
51
|
+
autoload :YouTube, 'omniauth/strategies/you_tube'
|
|
20
52
|
end
|
|
21
53
|
end
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
|
|
4
|
+
module OmniAuth
|
|
5
|
+
module Strategies
|
|
6
|
+
#
|
|
7
|
+
# Authenticate to Bitly utilizing OAuth 2.0 and retrieve
|
|
8
|
+
# basic user information.
|
|
9
|
+
#
|
|
10
|
+
# @example Basic Usage
|
|
11
|
+
# use OmniAuth::Strategies::Bitly, 'API Key', 'Secret Key'
|
|
12
|
+
class Bitly < OAuth2
|
|
13
|
+
# @param [Rack Application] app standard middleware application parameter
|
|
14
|
+
# @param [String] api_key the application id as [registered on Bitly](http://bit.ly/a/account)
|
|
15
|
+
# @param [String] secret_key the application secret as [registered on Bitly](http://bit.ly/a/account)
|
|
16
|
+
def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
|
|
17
|
+
client_options = {
|
|
18
|
+
:site => 'https://bit.ly',
|
|
19
|
+
:authorize_url => 'https://bit.ly/oauth/authorize',
|
|
20
|
+
:access_token_url => 'https://api-ssl.bit.ly/oauth/access_token'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
super(app, :bitly, api_key, secret_key, client_options, options, &block)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
protected
|
|
27
|
+
|
|
28
|
+
def user_data
|
|
29
|
+
{
|
|
30
|
+
'login' => @access_token['login'],
|
|
31
|
+
'api_key' => @access_token['apiKey']
|
|
32
|
+
}
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def auth_hash
|
|
36
|
+
OmniAuth::Utils.deep_merge(super, {
|
|
37
|
+
'uid' => @access_token['login'],
|
|
38
|
+
'user_info' => user_data,
|
|
39
|
+
'extra' => {'user_hash' => user_data}
|
|
40
|
+
})
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
|
|
4
|
+
module OmniAuth
|
|
5
|
+
module Strategies
|
|
6
|
+
#
|
|
7
|
+
# Authenticate to DailyMile utilizing OAuth 2.0 and retrieve
|
|
8
|
+
# basic user information.
|
|
9
|
+
#
|
|
10
|
+
# @example Basic Usage
|
|
11
|
+
# use OmniAuth::Strategies::DailyMile, 'CLIENT_ID', 'CLIENT_SECRET'
|
|
12
|
+
class Dailymile < OAuth2
|
|
13
|
+
# @param [Rack Application] app standard middleware application parameter
|
|
14
|
+
# @param [String] client_id the application id as [registered on Dailymile](http://www.dailymile.com/api/consumers/new)
|
|
15
|
+
# @param [String] cliend_secret the application secret as [registered on Dailymile](http://www.dailymile.com/api/consumers/new)
|
|
16
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
|
17
|
+
client_options = {
|
|
18
|
+
:site => 'https://api.dailymile.com/oauth',
|
|
19
|
+
:authorize_path => '/oauth/authorize',
|
|
20
|
+
:access_token_path => '/oauth/token'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
super(app, :dailymile, client_id, client_secret, client_options, options, &block)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
protected
|
|
27
|
+
|
|
28
|
+
def user_data
|
|
29
|
+
@data ||= MultiJson.decode(@access_token.get("/people/me.json"))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def request_phase
|
|
33
|
+
options[:response_type] ||= 'code'
|
|
34
|
+
super
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def callback_phase
|
|
38
|
+
options[:grant_type] ||= 'authorization_code'
|
|
39
|
+
super
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def user_info
|
|
43
|
+
{
|
|
44
|
+
'name' => user_data['display_name'],
|
|
45
|
+
'nickname' => user_data['username'],
|
|
46
|
+
'location' => user_data['location'],
|
|
47
|
+
'image' => user_data['photo_url'],
|
|
48
|
+
'description' => user_data['goal'],
|
|
49
|
+
'urls' => {
|
|
50
|
+
'dailymile' => user_data['url']
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def auth_hash
|
|
56
|
+
OmniAuth::Utils.deep_merge(super, {
|
|
57
|
+
'uid' => user_data["url"].split('/').last,
|
|
58
|
+
'user_info' => user_info,
|
|
59
|
+
'extra' => {'user_hash' => user_data}
|
|
60
|
+
})
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
|
|
4
|
+
module OmniAuth
|
|
5
|
+
module Strategies
|
|
6
|
+
class Doit < OAuth2
|
|
7
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
|
8
|
+
client_options = {
|
|
9
|
+
:site => 'https://openapi.doit.im',
|
|
10
|
+
:authorize_url => 'https://openapi.doit.im/oauth/authorize',
|
|
11
|
+
:access_token_url => 'https://openapi.doit.im/oauth/access_token'
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
super(app, :doit, consumer_key, consumer_secret, client_options, options, &block)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def user_data
|
|
20
|
+
@data ||= MultiJson.decode(@access_token.get(client.site+"/v1/settings"),{'Authorization'=> 'OAuth'+@access_token.token})
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def request_phase
|
|
24
|
+
options[:response_type] ||= "code"
|
|
25
|
+
super
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def callback_phase
|
|
29
|
+
options[:grant_type] ||= 'authorization_code'
|
|
30
|
+
super
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def user_info
|
|
34
|
+
{
|
|
35
|
+
'account' => user_data['account'],
|
|
36
|
+
'username'=> user_data['username'],
|
|
37
|
+
'nickname'=> user_data['nickname'],
|
|
38
|
+
'gender'=> user_data['gender'],
|
|
39
|
+
'week_start'=> user_data['week_start'],
|
|
40
|
+
'birthday_day'=> user_data['birthday_day'],
|
|
41
|
+
'birthday_month'=> user_data['birthday_month'],
|
|
42
|
+
'birthday_year'=> user_data['birthday_year'],
|
|
43
|
+
'language'=> user_data['language'],
|
|
44
|
+
'user_timezone'=> user_data['user_timezone'],
|
|
45
|
+
'remind_email'=> user_data['remind_email'],
|
|
46
|
+
'created'=> user_data['created'],
|
|
47
|
+
'updated'=> user_data['updated']
|
|
48
|
+
}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def auth_hash
|
|
52
|
+
OmniAuth::Utils.deep_merge(super, {
|
|
53
|
+
'uid' => user_data['id'],
|
|
54
|
+
'user_info' => user_info,
|
|
55
|
+
'extra' => {'user_hash' => user_data}
|
|
56
|
+
})
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_json'
|
|
2
3
|
|
|
3
4
|
module OmniAuth
|
|
4
5
|
module Strategies
|
|
@@ -10,13 +11,43 @@ module OmniAuth
|
|
|
10
11
|
# use OmniAuth::Strategies::Dopplr, 'consumerkey', 'consumersecret'
|
|
11
12
|
#
|
|
12
13
|
class Dopplr < OmniAuth::Strategies::OAuth
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
# Initialize the Dopplr strategy.
|
|
15
|
+
#
|
|
16
|
+
# @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
|
|
17
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
|
18
|
+
client_options = {
|
|
19
|
+
:site => 'https://www.dopplr.com',
|
|
20
|
+
:request_token_path => "/oauth/request_token",
|
|
21
|
+
:access_token_path => "/oauth/access_token",
|
|
22
|
+
:authorize_path => "/oauth/authorize"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
super(app, :dopplr, consumer_key, consumer_secret, client_options, options, &block)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def user_data
|
|
29
|
+
@data ||= MultiJson.decode(@access_token.get('/oauthapi/whoami').body)['whoami']
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def user_info
|
|
33
|
+
{
|
|
34
|
+
'nickname' => user_data["nick"],
|
|
35
|
+
'first_name' => user_data["forename"],
|
|
36
|
+
'last_name' => user_data["surname"],
|
|
37
|
+
'name' => "#{user_data['forename']} #{user_data['surname']}",
|
|
38
|
+
'urls' => {
|
|
39
|
+
'Dopplr' => user_data["dopplr_url"],
|
|
40
|
+
'DopplrMobile' => user_data["mobile_url"],
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def auth_hash
|
|
46
|
+
OmniAuth::Utils.deep_merge(super, {
|
|
47
|
+
'uid' => user_data['nick'],
|
|
48
|
+
'user_info' => user_info
|
|
49
|
+
})
|
|
50
|
+
end
|
|
20
51
|
end
|
|
21
52
|
end
|
|
22
53
|
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,54 @@
|
|
|
1
|
+
require 'omniauth/oauth'
|
|
2
|
+
require 'multi_json'
|
|
3
|
+
require 'evernote'
|
|
4
|
+
|
|
5
|
+
module OmniAuth
|
|
6
|
+
module Strategies
|
|
7
|
+
#
|
|
8
|
+
# Authenticate to Evernote via OAuth and retrieve an access token for API usage
|
|
9
|
+
#
|
|
10
|
+
# Usage:
|
|
11
|
+
#
|
|
12
|
+
# use OmniAuth::Strategies::Evernote, 'consumerkey', 'consumersecret'
|
|
13
|
+
#
|
|
14
|
+
class Evernote < OmniAuth::Strategies::OAuth
|
|
15
|
+
# Initialize the Evernote strategy.
|
|
16
|
+
#
|
|
17
|
+
# @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
|
|
18
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
|
19
|
+
client_options = {
|
|
20
|
+
:site => 'https://www.evernote.com',
|
|
21
|
+
:request_token_path => '/oauth',
|
|
22
|
+
:access_token_path => '/oauth',
|
|
23
|
+
:authorize_path => '/OAuth.action',
|
|
24
|
+
:oauth_signature_method => 'PLAINTEXT'
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
super(app, :evernote, consumer_key, consumer_secret, client_options, options, &block)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def auth_hash
|
|
31
|
+
OmniAuth::Utils.deep_merge(super, {
|
|
32
|
+
'uid' => user_data.id,
|
|
33
|
+
'user_info' => user_info,
|
|
34
|
+
'extra' => user_data
|
|
35
|
+
})
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def user_info
|
|
39
|
+
{
|
|
40
|
+
'name' => user_data.name,
|
|
41
|
+
'nickname' => user_data.username,
|
|
42
|
+
}
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def user_data
|
|
46
|
+
@user_data ||= begin
|
|
47
|
+
user_store_url = consumer.site + '/edam/user'
|
|
48
|
+
client = ::Evernote::Client.new(::Evernote::EDAM::UserStore::UserStore::Client, user_store_url, {})
|
|
49
|
+
client.getUser(@access_token.token)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|