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
@@ -7,39 +7,57 @@ module OmniAuth
|
|
7
7
|
# basic user information.
|
8
8
|
#
|
9
9
|
# @example Basic Usage
|
10
|
-
# use OmniAuth::Strategies::Facebook, '
|
10
|
+
# use OmniAuth::Strategies::Facebook, 'client_id', 'client_secret'
|
11
11
|
class Facebook < OAuth2
|
12
12
|
# @param [Rack Application] app standard middleware application parameter
|
13
|
-
# @param [String]
|
14
|
-
# @param [String]
|
13
|
+
# @param [String] client_id the application id as [registered on Facebook](http://www.facebook.com/developers/)
|
14
|
+
# @param [String] client_secret the application secret as registered on Facebook
|
15
15
|
# @option options [String] :scope ('email,offline_access') comma-separated extended permissions such as `email` and `manage_pages`
|
16
|
-
def initialize(app,
|
17
|
-
|
18
|
-
super(app, :facebook, app_id, app_secret, options)
|
16
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
17
|
+
super(app, :facebook, client_id, client_secret, {:site => 'https://graph.facebook.com/'}, options, &block)
|
19
18
|
end
|
20
|
-
|
19
|
+
|
21
20
|
def user_data
|
22
21
|
@data ||= MultiJson.decode(@access_token.get('/me', {}, { "Accept-Language" => "en-us,en;"}))
|
23
22
|
end
|
24
|
-
|
23
|
+
|
25
24
|
def request_phase
|
26
25
|
options[:scope] ||= "email,offline_access"
|
27
26
|
super
|
28
27
|
end
|
29
|
-
|
28
|
+
|
29
|
+
def build_access_token
|
30
|
+
if facebook_session.nil? || facebook_session.empty?
|
31
|
+
super
|
32
|
+
else
|
33
|
+
@access_token = ::OAuth2::AccessToken.new(client, facebook_session['access_token'])
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def facebook_session
|
38
|
+
session_cookie = request.cookies["fbs_#{client.id}"]
|
39
|
+
if session_cookie
|
40
|
+
@facebook_session ||= Rack::Utils.parse_query(request.cookies["fbs_#{client.id}"].gsub('"', ''))
|
41
|
+
else
|
42
|
+
nil
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
30
46
|
def user_info
|
31
47
|
{
|
32
48
|
'nickname' => user_data["link"].split('/').last,
|
49
|
+
'email' => (user_data["email"] if user_data["email"]),
|
33
50
|
'first_name' => user_data["first_name"],
|
34
51
|
'last_name' => user_data["last_name"],
|
35
52
|
'name' => "#{user_data['first_name']} #{user_data['last_name']}",
|
53
|
+
'image' => "http://graph.facebook.com/#{user_data['id']}/picture?type=square",
|
36
54
|
'urls' => {
|
37
55
|
'Facebook' => user_data["link"],
|
38
56
|
'Website' => user_data["website"],
|
39
57
|
}
|
40
58
|
}
|
41
59
|
end
|
42
|
-
|
60
|
+
|
43
61
|
def auth_hash
|
44
62
|
OmniAuth::Utils.deep_merge(super, {
|
45
63
|
'uid' => user_data['id'],
|
@@ -49,4 +67,4 @@ module OmniAuth
|
|
49
67
|
end
|
50
68
|
end
|
51
69
|
end
|
52
|
-
end
|
70
|
+
end
|
@@ -1,39 +1,62 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
1
4
|
module OmniAuth
|
2
5
|
module Strategies
|
3
|
-
class Foursquare <
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
class Foursquare < OAuth2
|
7
|
+
# Initialize the middleware
|
8
|
+
#
|
9
|
+
# @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
|
10
|
+
# @option options [Boolean, false] :mobile When true, use the mobile sign-in interface.
|
11
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
12
|
+
options[:sign_in] ||= true
|
13
|
+
super(app, :foursquare, client_id, client_secret, {
|
14
|
+
:site => "https://api.foursquare.com/v2",
|
15
|
+
:authorize_url => authorize_url(options),
|
16
|
+
:access_token_url => "https://foursquare.com/oauth2/access_token"
|
17
|
+
}, options, &block)
|
7
18
|
end
|
8
|
-
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
})
|
19
|
+
|
20
|
+
def authorize_url(options)
|
21
|
+
"https://foursquare.com/#{'mobile/' if options[:mobile]}oauth2/#{options[:sign_in] ? 'authenticate' : 'authorize'}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def user_data
|
25
|
+
@data ||= MultiJson.decode(@access_token.get(client.site+'/users/self', {'oauth_token' => @access_token.token}))
|
26
|
+
end
|
27
|
+
|
28
|
+
def request_phase
|
29
|
+
options[:response_type] ||= 'code'
|
30
|
+
super
|
15
31
|
end
|
16
|
-
|
32
|
+
|
33
|
+
def callback_phase
|
34
|
+
options[:grant_type] ||= 'authorization_code'
|
35
|
+
super
|
36
|
+
end
|
37
|
+
|
17
38
|
def user_info
|
18
|
-
user_hash = self.user_hash
|
19
|
-
|
20
39
|
{
|
21
|
-
'nickname' =>
|
22
|
-
'first_name' =>
|
23
|
-
'last_name' =>
|
24
|
-
'email' =>
|
25
|
-
'name' => "#{
|
26
|
-
# 'location' =>
|
27
|
-
'image' =>
|
28
|
-
# 'description' =>
|
29
|
-
'phone' =>
|
40
|
+
'nickname' => user_data['response']['user']['contact']['twitter'],
|
41
|
+
'first_name' => user_data['response']['user']['firstName'],
|
42
|
+
'last_name' => user_data['response']['user']['lastName'],
|
43
|
+
'email' => user_data['response']['user']['contact']['email'],
|
44
|
+
'name' => "#{user_data['response']['user']['firstName']} #{user_data['response']['user']['lastName']}".strip,
|
45
|
+
# 'location' => user_data['response']['user']['location'],
|
46
|
+
'image' => user_data['response']['user']['photo'],
|
47
|
+
# 'description' => user_data['response']['user']['description'],
|
48
|
+
'phone' => user_data['response']['user']['contact']['phone'],
|
30
49
|
'urls' => {}
|
31
50
|
}
|
32
51
|
end
|
33
|
-
|
34
|
-
def
|
35
|
-
|
52
|
+
|
53
|
+
def auth_hash
|
54
|
+
OmniAuth::Utils.deep_merge(super, {
|
55
|
+
'uid' => user_data['response']['user']['id'],
|
56
|
+
'user_info' => user_info,
|
57
|
+
'extra' => {'user_hash' => user_data['response']['user']}
|
58
|
+
})
|
36
59
|
end
|
37
60
|
end
|
38
61
|
end
|
39
|
-
end
|
62
|
+
end
|
@@ -3,26 +3,29 @@ require 'multi_json'
|
|
3
3
|
|
4
4
|
module OmniAuth
|
5
5
|
module Strategies
|
6
|
-
# OAuth 2.0 based authentication with GitHub. In order to
|
6
|
+
# OAuth 2.0 based authentication with GitHub. In order to
|
7
7
|
# sign up for an application, you need to [register an application](http://github.com/account/applications/new)
|
8
8
|
# and provide the proper credentials to this middleware.
|
9
9
|
class GitHub < OAuth2
|
10
10
|
# @param [Rack Application] app standard middleware application argument
|
11
|
-
# @param [String]
|
12
|
-
# @param [String]
|
13
|
-
def initialize(app,
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
# @param [String] client_id the application ID for your client
|
12
|
+
# @param [String] client_secret the application secret
|
13
|
+
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
14
|
+
client_options = {
|
15
|
+
:site => 'https://github.com/',
|
16
|
+
:authorize_path => '/login/oauth/authorize',
|
17
|
+
:access_token_path => '/login/oauth/access_token'
|
18
|
+
}
|
19
|
+
|
20
|
+
super(app, :github, client_id, client_secret, client_options, options, &block)
|
18
21
|
end
|
19
|
-
|
22
|
+
|
20
23
|
protected
|
21
|
-
|
24
|
+
|
22
25
|
def user_data
|
23
26
|
@data ||= MultiJson.decode(@access_token.get('/api/v2/json/user/show'))['user']
|
24
27
|
end
|
25
|
-
|
28
|
+
|
26
29
|
def user_info
|
27
30
|
{
|
28
31
|
'nickname' => user_data["login"],
|
@@ -34,7 +37,7 @@ module OmniAuth
|
|
34
37
|
}
|
35
38
|
}
|
36
39
|
end
|
37
|
-
|
40
|
+
|
38
41
|
def auth_hash
|
39
42
|
OmniAuth::Utils.deep_merge(super, {
|
40
43
|
'uid' => user_data['id'],
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'multi_xml'
|
2
|
+
require 'omniauth/oauth'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
class Goodreads < OmniAuth::Strategies::OAuth
|
7
|
+
|
8
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
9
|
+
client_options = {
|
10
|
+
:site => 'http://www.goodreads.com',
|
11
|
+
}
|
12
|
+
@consumer_key = consumer_key
|
13
|
+
super(app, :goodreads, consumer_key, consumer_secret, client_options, options, &block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def auth_hash
|
17
|
+
hash = user_hash(@access_token)
|
18
|
+
|
19
|
+
OmniAuth::Utils.deep_merge(super, {
|
20
|
+
'uid' => hash.delete('id'),
|
21
|
+
'user_info' => hash
|
22
|
+
})
|
23
|
+
end
|
24
|
+
|
25
|
+
def user_hash(access_token)
|
26
|
+
authenticated_user = MultiXml.parse(@access_token.get('/api/auth_user').body)
|
27
|
+
id = authenticated_user.xpath('GoodreadsResponse/user').attribute('id').value.to_i
|
28
|
+
response_doc = MultiXml.parse(open("http://www.goodreads.com/user/show/#{id}.xml?key=#{@consumer_key}").read)
|
29
|
+
user = response_doc.xpath('GoodreadsResponse/user')
|
30
|
+
|
31
|
+
hash = {
|
32
|
+
'id' => id,
|
33
|
+
'name' => user.xpath('name').text,
|
34
|
+
'user_name' => user.xpath('user_name').text,
|
35
|
+
'image_url' => user.xpath('image_url').text,
|
36
|
+
'about' => user.xpath('about').text,
|
37
|
+
'location' => user.xpath('location').text,
|
38
|
+
'website' => user.xpath('website').text,
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module OmniAuth
|
5
|
+
module Strategies
|
6
|
+
#
|
7
|
+
# Authenticate to Google via OAuth and retrieve basic
|
8
|
+
# user information.
|
9
|
+
#
|
10
|
+
# Usage:
|
11
|
+
#
|
12
|
+
# use OmniAuth::Strategies::Google, 'consumerkey', 'consumersecret'
|
13
|
+
#
|
14
|
+
class Google < OmniAuth::Strategies::OAuth
|
15
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
16
|
+
client_options = {
|
17
|
+
:site => 'https://www.google.com',
|
18
|
+
:request_token_path => '/accounts/OAuthGetRequestToken',
|
19
|
+
:access_token_path => '/accounts/OAuthGetAccessToken',
|
20
|
+
:authorize_path => '/accounts/OAuthAuthorizeToken'
|
21
|
+
}
|
22
|
+
|
23
|
+
google_contacts_auth = "http://www.google.com/m8/feeds"
|
24
|
+
options[:scope] ||= google_contacts_auth
|
25
|
+
options[:scope] << " #{google_contacts_auth}" unless options[:scope].include?(google_contacts_auth)
|
26
|
+
|
27
|
+
super(app, :google, consumer_key, consumer_secret, client_options, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def auth_hash
|
31
|
+
ui = user_info
|
32
|
+
OmniAuth::Utils.deep_merge(super, {
|
33
|
+
'uid' => ui['uid'],
|
34
|
+
'user_info' => ui,
|
35
|
+
'extra' => {'user_hash' => user_hash}
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
def user_info
|
40
|
+
email = user_hash['feed']['id']['$t']
|
41
|
+
|
42
|
+
name = user_hash['feed']['author'].first['name']['$t']
|
43
|
+
name = email if name.strip == '(unknown)'
|
44
|
+
|
45
|
+
{
|
46
|
+
'email' => email,
|
47
|
+
'uid' => email,
|
48
|
+
'name' => name
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
52
|
+
def user_hash
|
53
|
+
# Google is very strict about keeping authorization and
|
54
|
+
# authentication separated.
|
55
|
+
# They give no endpoint to get a user's profile directly that I can
|
56
|
+
# find. We *can* get their name and email out of the contacts feed,
|
57
|
+
# however. It will fail in the extremely rare case of a user who has
|
58
|
+
# a Google Account but has never even signed up for Gmail. This has
|
59
|
+
# not been seen in the field.
|
60
|
+
@user_hash ||= MultiJson.decode(@access_token.get("http://www.google.com/m8/feeds/contacts/default/full?max-results=1&alt=json").body)
|
61
|
+
end
|
62
|
+
|
63
|
+
# Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call
|
64
|
+
def request_phase
|
65
|
+
request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => options[:scope]})
|
66
|
+
session['oauth'] ||= {}
|
67
|
+
session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
|
68
|
+
r = Rack::Response.new
|
69
|
+
|
70
|
+
if request_token.callback_confirmed?
|
71
|
+
r.redirect(request_token.authorize_url)
|
72
|
+
else
|
73
|
+
r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
|
74
|
+
end
|
75
|
+
|
76
|
+
r.finish
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -14,24 +14,27 @@ module OmniAuth
|
|
14
14
|
# @param [String] api_key the application id as [registered on Gowalla](http://gowalla.com/api/keys)
|
15
15
|
# @param [String] secret_key the application secret as [registered on Gowalla](http://gowalla.com/api/keys)
|
16
16
|
# @option options ['read','read-write'] :scope ('read') the scope of your authorization request; must be `read` or `read-write`
|
17
|
-
def initialize(app, api_key, secret_key, options = {})
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
|
18
|
+
client_options = {
|
19
|
+
:site => 'https://api.gowalla.com/api/oauth',
|
20
|
+
:authorize_url => 'https://gowalla.com/api/oauth/new',
|
21
|
+
:access_token_url => 'https://api.gowalla.com/api/oauth/token'
|
22
|
+
}
|
23
|
+
|
24
|
+
super(app, :gowalla, api_key, secret_key, client_options, options, &block)
|
22
25
|
end
|
23
|
-
|
26
|
+
|
24
27
|
protected
|
25
|
-
|
28
|
+
|
26
29
|
def user_data
|
27
30
|
@data ||= MultiJson.decode(@access_token.get("/users/me.json"))
|
28
31
|
end
|
29
|
-
|
32
|
+
|
30
33
|
def request_phase
|
31
34
|
options[:scope] ||= "read"
|
32
35
|
super
|
33
36
|
end
|
34
|
-
|
37
|
+
|
35
38
|
def user_info
|
36
39
|
{
|
37
40
|
'name' => "#{user_data['first_name']} #{user_data['last_name']}",
|
@@ -48,7 +51,7 @@ module OmniAuth
|
|
48
51
|
}
|
49
52
|
}
|
50
53
|
end
|
51
|
-
|
54
|
+
|
52
55
|
def auth_hash
|
53
56
|
OmniAuth::Utils.deep_merge(super, {
|
54
57
|
'uid' => user_data["url"].split('/').last,
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'omniauth/oauth'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
|
5
|
+
module OmniAuth
|
6
|
+
module Strategies
|
7
|
+
class Hyves < OmniAuth::Strategies::OAuth
|
8
|
+
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
9
|
+
client_options = {
|
10
|
+
:request_token_path => request_token_path,
|
11
|
+
:authorize_path => "http://www.hyves.nl/api/authorize",
|
12
|
+
:access_token_path => access_token_path,
|
13
|
+
:http_method => :get,
|
14
|
+
:scheme => :header
|
15
|
+
}
|
16
|
+
super(app, :hyves, consumer_key, consumer_secret, client_options, options, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def auth_hash
|
20
|
+
hash = user_hash(@access_token)
|
21
|
+
|
22
|
+
{
|
23
|
+
"provider" => "hyves",
|
24
|
+
"uid" => hash["userid"],
|
25
|
+
"user_info" => {
|
26
|
+
"name" => hash["firstname"] + " " + hash["lastname"],
|
27
|
+
"first_name" => hash["firstname"],
|
28
|
+
"last_name" => hash["lastname"]
|
29
|
+
},
|
30
|
+
"credentials" => {
|
31
|
+
"token" => @access_token.token,
|
32
|
+
"secret" => @access_token.secret
|
33
|
+
}
|
34
|
+
}
|
35
|
+
end
|
36
|
+
|
37
|
+
def user_hash(access_token)
|
38
|
+
rsp = MultiJson.decode( access_token.get("http://data.hyves-api.nl/?userid=#{access_token.params[:userid]}&ha_method=users.get&#{default_options}").body )
|
39
|
+
rsp["user"].first
|
40
|
+
end
|
41
|
+
|
42
|
+
def request_token_path
|
43
|
+
"http://data.hyves-api.nl/?#{request_token_options}&#{default_options}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def access_token_path
|
47
|
+
"http://data.hyves-api.nl/?#{access_token_options}&#{default_options}"
|
48
|
+
end
|
49
|
+
|
50
|
+
def default_options
|
51
|
+
to_params( { :ha_version => "2.0", :ha_format => "json", :ha_fancylayout => false } )
|
52
|
+
end
|
53
|
+
|
54
|
+
def request_token_options
|
55
|
+
to_params( { :methods => "users.get,friends.get,wwws.create", :ha_method => "auth.requesttoken", :strict_oauth_spec_response => true } )
|
56
|
+
end
|
57
|
+
|
58
|
+
def access_token_options
|
59
|
+
to_params( { :ha_method => "auth.accesstoken", :strict_oauth_spec_response => true } )
|
60
|
+
end
|
61
|
+
|
62
|
+
def to_params(options)
|
63
|
+
options.collect { |key, value| "#{key}=#{value}"}.join('&')
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|