oa-oauth 0.2.0.beta5 → 0.2.0

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.
@@ -4,6 +4,7 @@ module OmniAuth
4
4
  module Strategies
5
5
  autoload :OAuth, 'omniauth/strategies/oauth'
6
6
  autoload :OAuth2, 'omniauth/strategies/oauth2'
7
+ autoload :XAuth, 'omniauth/strategies/xauth'
7
8
 
8
9
  autoload :Twitter, 'omniauth/strategies/twitter'
9
10
  autoload :LinkedIn, 'omniauth/strategies/linked_in'
@@ -28,5 +29,12 @@ module OmniAuth
28
29
  autoload :YouTube, 'omniauth/strategies/you_tube'
29
30
  autoload :Hyves, 'omniauth/strategies/hyves'
30
31
  autoload :Miso, 'omniauth/strategies/miso'
32
+ autoload :Dailymile, 'omniauth/strategies/dailymile'
33
+ autoload :Instagram, 'omniauth/strategies/instagram'
34
+ autoload :Mixi, 'omniauth/strategies/mixi'
35
+ autoload :Evernote, 'omniauth/strategies/evernote'
36
+ autoload :Doit, 'omniauth/strategies/doit'
37
+ autoload :Instapaper, 'omniauth/strategies/instapaper'
38
+ autoload :TradeMe, 'omniauth/strategies/trade_me'
31
39
  end
32
40
  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
@@ -0,0 +1,59 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ begin
5
+ require 'evernote'
6
+ rescue LoadError => e
7
+ raise "Omniauth Evernote strategy requires 'evernote' gem. Add it to your Gemfile: gem 'evernote'"
8
+ end
9
+
10
+ module OmniAuth
11
+ module Strategies
12
+ #
13
+ # Authenticate to Evernote via OAuth and retrieve an access token for API usage
14
+ #
15
+ # Usage:
16
+ #
17
+ # use OmniAuth::Strategies::Evernote, 'consumerkey', 'consumersecret'
18
+ #
19
+ class Evernote < OmniAuth::Strategies::OAuth
20
+ # Initialize the Evernote strategy.
21
+ #
22
+ # @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
23
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
24
+ client_options = {
25
+ :site => 'https://www.evernote.com',
26
+ :request_token_path => '/oauth',
27
+ :access_token_path => '/oauth',
28
+ :authorize_path => '/OAuth.action',
29
+ :oauth_signature_method => 'PLAINTEXT'
30
+ }
31
+
32
+ super(app, :evernote, consumer_key, consumer_secret, client_options, options, &block)
33
+ end
34
+
35
+ def auth_hash
36
+ OmniAuth::Utils.deep_merge(super, {
37
+ 'uid' => user_data.id,
38
+ 'user_info' => user_info,
39
+ 'extra' => user_data
40
+ })
41
+ end
42
+
43
+ def user_info
44
+ {
45
+ 'name' => user_data.name,
46
+ 'nickname' => user_data.username,
47
+ }
48
+ end
49
+
50
+ def user_data
51
+ @user_data ||= begin
52
+ user_store_url = consumer.site + '/edam/user'
53
+ client = ::Evernote::Client.new(::Evernote::EDAM::UserStore::UserStore::Client, user_store_url, {})
54
+ client.getUser(@access_token.token)
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -26,6 +26,23 @@ module OmniAuth
26
26
  super
27
27
  end
28
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
+
29
46
  def user_info
30
47
  {
31
48
  'nickname' => user_data["link"].split('/').last,
@@ -50,4 +67,4 @@ module OmniAuth
50
67
  end
51
68
  end
52
69
  end
53
- end
70
+ end
@@ -3,7 +3,7 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- #
6
+ #
7
7
  # Authenticate to Google via OAuth and retrieve basic
8
8
  # user information.
9
9
  #
@@ -23,10 +23,10 @@ module OmniAuth
23
23
  google_contacts_auth = "http://www.google.com/m8/feeds"
24
24
  options[:scope] ||= google_contacts_auth
25
25
  options[:scope] << " #{google_contacts_auth}" unless options[:scope].include?(google_contacts_auth)
26
-
26
+
27
27
  super(app, :google, consumer_key, consumer_secret, client_options, options)
28
28
  end
29
-
29
+
30
30
  def auth_hash
31
31
  ui = user_info
32
32
  OmniAuth::Utils.deep_merge(super, {
@@ -35,20 +35,20 @@ module OmniAuth
35
35
  'extra' => {'user_hash' => user_hash}
36
36
  })
37
37
  end
38
-
38
+
39
39
  def user_info
40
40
  email = user_hash['feed']['id']['$t']
41
-
41
+
42
42
  name = user_hash['feed']['author'].first['name']['$t']
43
43
  name = email if name.strip == '(unknown)'
44
-
44
+
45
45
  {
46
46
  'email' => email,
47
47
  'uid' => email,
48
48
  'name' => name
49
49
  }
50
50
  end
51
-
51
+
52
52
  def user_hash
53
53
  # Google is very strict about keeping authorization and
54
54
  # authentication separated.
@@ -63,14 +63,14 @@ module OmniAuth
63
63
  # Monkeypatch OmniAuth to pass the scope in the consumer.get_request_token call
64
64
  def request_phase
65
65
  request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => options[:scope]})
66
-
67
- (session['oauth']||={})[name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
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
68
  r = Rack::Response.new
69
69
 
70
70
  if request_token.callback_confirmed?
71
71
  r.redirect(request_token.authorize_url)
72
72
  else
73
- r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
73
+ r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
74
74
  end
75
75
 
76
76
  r.finish
@@ -0,0 +1,56 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ # Authenticate to Facebook utilizing OAuth 2.0 and retrieve
7
+ # basic user information.
8
+ #
9
+ # @example Basic Usage
10
+ # use OmniAuth::Strategies::Instagram, 'client_id', 'client_secret'
11
+ class Instagram < OAuth2
12
+ # @option options [String] :scope separate the scopes by a space
13
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
14
+ client_options = {
15
+ :site => "https://api.instagram.com/",
16
+ :authorize_url => "/oauth/authorize",
17
+ :access_token_url => "/oauth/access_token"
18
+ }
19
+
20
+ super(app, :instagram, client_id, client_secret, client_options, options, &block)
21
+ end
22
+
23
+ def request_phase
24
+ options[:scope] ||= "basic"
25
+ options[:response_type] ||= 'code'
26
+ super
27
+ end
28
+
29
+ def callback_phase
30
+ options[:grant_type] ||= 'authorization_code'
31
+ super
32
+ end
33
+
34
+ def user_data
35
+ @data ||= MultiJson.decode(@access_token.get("/v1/users/self"))
36
+ end
37
+
38
+ def user_info
39
+ {
40
+ 'nickname' => user_data['data']['username'],
41
+ 'name' => user_data['data']['full_name'],
42
+ 'image' => user_data['data']['profile_picture'],
43
+ 'urls' => {}
44
+ }
45
+ end
46
+
47
+ def auth_hash
48
+ OmniAuth::Utils.deep_merge(super, {
49
+ 'uid' => user_data['data']['id'],
50
+ 'user_info' => user_info,
51
+ 'extra' => {'user_hash' => user_data['data']}
52
+ })
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,40 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class Instapaper < OmniAuth::Strategies::XAuth
7
+
8
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
9
+ client_options = {
10
+ :title => 'Instapaper',
11
+ :site => 'https://www.instapaper.com',
12
+ :access_token_path => '/api/1/oauth/access_token'
13
+ }
14
+ super(app, :instapaper, 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('/api/1/account/verify_credentials').body)[0]
21
+ end
22
+
23
+ def user_info
24
+ {
25
+ 'nickname' => user_data['username'],
26
+ 'name' => user_data['username']
27
+ }
28
+ end
29
+
30
+ def auth_hash
31
+ OmniAuth::Utils.deep_merge(super, {
32
+ 'uid' => user_data['user_id'],
33
+ 'user_info' => user_info
34
+ })
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
@@ -35,6 +35,7 @@ module OmniAuth
35
35
  'id' => person.xpath('id').text,
36
36
  'first_name' => person.xpath('first-name').text,
37
37
  'last_name' => person.xpath('last-name').text,
38
+ 'nickname' => person.xpath('public-profile-url').text.split('/').last,
38
39
  'location' => person.xpath('location/name').text,
39
40
  'image' => person.xpath('picture-url').text,
40
41
  'description' => person.xpath('headline').text,
@@ -0,0 +1,59 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ # Authenticate to Facebook utilizing OAuth 2.0 and retrieve
7
+ # basic user information.
8
+ #
9
+ # @example Basic Usage
10
+ # use OmniAuth::Strategies::Mixi, 'client_id', 'client_secret'
11
+ class Mixi < OAuth2
12
+ # @option options [String] :scope separate the scopes by a space
13
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
14
+ client_options = {
15
+ :site => "https://mixi.jp/",
16
+ :authorize_url => "/connect_authorize.pl",
17
+ :access_token_url => "https://secure.mixi-platform.com/2/token"
18
+ }
19
+
20
+ super(app, :mixi, client_id, client_secret, client_options, options, &block)
21
+ end
22
+
23
+ def user_data
24
+ @data ||= MultiJson.decode(@access_token.get(
25
+ "http://api.mixi-platform.com/2/people/@me/@self",
26
+ {'oauth_token' => @access_token.token}
27
+ ))
28
+ end
29
+
30
+ def request_phase
31
+ options[:scope] ||= "r_profile"
32
+ options[:display] ||= "pc"
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
+ 'nickname' => user_data['entry']['displayName'],
45
+ 'image' => user_data['entry']['thumbnailUrl'],
46
+ 'urls' => {:profile => user_data['entry']['profileUrl']}
47
+ }
48
+ end
49
+
50
+ def auth_hash
51
+ OmniAuth::Utils.deep_merge(super, {
52
+ 'uid' => user_data['entry']['id'],
53
+ 'user_info' => user_info,
54
+ 'extra' => {'user_hash' => user_data['entry']}
55
+ })
56
+ end
57
+ end
58
+ end
59
+ end
@@ -10,7 +10,7 @@ module OmniAuth
10
10
  #
11
11
  class Netflix < OmniAuth::Strategies::OAuth
12
12
  def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
13
- opts = {
13
+ opts = {
14
14
  :site => 'http://api.netflix.com',
15
15
  :request_token_path => "/oauth/request_token",
16
16
  :access_token_path => "/oauth/access_token",
@@ -18,12 +18,13 @@ module OmniAuth
18
18
  }
19
19
  super(app, :netflix, consumer_key, consumer_secret, opts, options, &block)
20
20
  end
21
-
21
+
22
22
  def request_phase
23
23
  request_token = consumer.get_request_token(:oauth_callback => callback_url)
24
- (session['oauth']||={})[name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
24
+ session['oauth'] ||= {}
25
+ session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
25
26
  r = Rack::Response.new
26
-
27
+
27
28
  if request_token.callback_confirmed?
28
29
  r.redirect(request_token.authorize_url(
29
30
  :oauth_consumer_key => consumer.key
@@ -32,12 +33,12 @@ module OmniAuth
32
33
  r.redirect(request_token.authorize_url(
33
34
  :oauth_callback => callback_url,
34
35
  :oauth_consumer_key => consumer.key
35
- ))
36
+ ))
36
37
  end
37
-
38
+
38
39
  r.finish
39
40
  end
40
-
41
+
41
42
  def auth_hash
42
43
  OmniAuth::Utils.deep_merge(super, {
43
44
  'uid' => user_hash['user']['user_id'],
@@ -45,16 +46,17 @@ module OmniAuth
45
46
  'extra' => { 'user_hash' => user_hash['user'] }
46
47
  })
47
48
  end
48
-
49
+
49
50
  def user_info
50
51
  user = user_hash['user']
51
- {
52
- 'nickname' => user['nickname'],
52
+ {
53
+ 'nickname' => user['nickname'],
53
54
  'first_name' => user['first_name'],
54
55
  'last_name' => user['last_name'],
56
+ 'name' => "#{user['first_name']} #{user['last_name']}"
55
57
  }
56
58
  end
57
-
59
+
58
60
  def user_hash
59
61
  @user_hash ||= MultiJson.decode(@access_token.get("http://api.netflix.com/users/#{@access_token.params[:user_id]}?output=json").body)
60
62
  end
@@ -11,10 +11,15 @@ module OmniAuth
11
11
  self.consumer_secret = consumer_secret
12
12
  self.consumer_options = consumer_options
13
13
  super
14
+ self.options[:open_timeout] ||= 30
15
+ self.options[:read_timeout] ||= 30
14
16
  end
15
17
 
16
18
  def consumer
17
- ::OAuth::Consumer.new(consumer_key, consumer_secret, consumer_options.merge(options[:client_options] || options[:consumer_options] || {}))
19
+ consumer = ::OAuth::Consumer.new(consumer_key, consumer_secret, consumer_options.merge(options[:client_options] || options[:consumer_options] || {}))
20
+ consumer.http.open_timeout = options[:open_timeout] if options[:open_timeout]
21
+ consumer.http.read_timeout = options[:read_timeout] if options[:read_timeout]
22
+ consumer
18
23
  end
19
24
 
20
25
  attr_reader :name
@@ -22,7 +27,8 @@ module OmniAuth
22
27
 
23
28
  def request_phase
24
29
  request_token = consumer.get_request_token(:oauth_callback => callback_url)
25
- (session['oauth']||={})[name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
30
+ session['oauth'] ||= {}
31
+ session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
26
32
  r = Rack::Response.new
27
33
 
28
34
  if request_token.callback_confirmed?
@@ -32,6 +38,8 @@ module OmniAuth
32
38
  end
33
39
 
34
40
  r.finish
41
+ rescue ::Timeout::Error => e
42
+ fail!(:timeout, e)
35
43
  end
36
44
 
37
45
  def callback_phase
@@ -46,6 +54,8 @@ module OmniAuth
46
54
 
47
55
  @access_token = request_token.get_access_token(opts)
48
56
  super
57
+ rescue ::Timeout::Error => e
58
+ fail!(:timeout, e)
49
59
  rescue ::Net::HTTPFatalError => e
50
60
  fail!(:service_unavailable, e)
51
61
  rescue ::OAuth::Unauthorized => e
@@ -57,14 +57,13 @@ module OmniAuth
57
57
  def request_phase
58
58
  redirect client.web_server.authorize_url({:redirect_uri => callback_url}.merge(options))
59
59
  end
60
-
60
+
61
61
  def callback_phase
62
62
  if request.params['error'] || request.params['error_reason']
63
63
  raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
64
64
  end
65
65
 
66
- verifier = request.params['code']
67
- @access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
66
+ @access_token = build_access_token
68
67
 
69
68
  if @access_token.expires? && @access_token.expires_in <= 0
70
69
  client.request(:post, client.access_token_url, {
@@ -82,6 +81,11 @@ module OmniAuth
82
81
  rescue ::MultiJson::DecodeError => e
83
82
  fail!(:invalid_response, e)
84
83
  end
84
+
85
+ def build_access_token
86
+ verifier = request.params['code']
87
+ client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
88
+ end
85
89
 
86
90
  def auth_hash
87
91
  OmniAuth::Utils.deep_merge(super, {
@@ -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
@@ -0,0 +1,67 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ class XAuth
7
+ include OmniAuth::Strategy
8
+
9
+ attr_reader :name
10
+ attr_accessor :consumer_key, :consumer_secret, :consumer_options
11
+
12
+ def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block)
13
+ self.consumer_key = consumer_key
14
+ self.consumer_secret = consumer_secret
15
+ self.consumer_options = consumer_options
16
+ super
17
+ end
18
+
19
+ def request_phase
20
+ session['oauth'] ||= {}
21
+ if env['REQUEST_METHOD'] == 'GET'
22
+ get_credentials
23
+ else
24
+ session['omniauth.xauth'] = { 'x_auth_mode' => 'client_auth', 'x_auth_username' => request['username'], 'x_auth_password' => request['password'] }
25
+ redirect callback_path
26
+ end
27
+ end
28
+
29
+ def get_credentials
30
+ OmniAuth::Form.build(consumer_options[:title] || "xAuth Credentials") do
31
+ text_field 'Username', 'username'
32
+ password_field 'Password', 'password'
33
+ end.to_response
34
+ end
35
+
36
+ def consumer
37
+ ::OAuth::Consumer.new(consumer_key, consumer_secret, consumer_options.merge(options[:client_options] || options[:consumer_options] || {}))
38
+ end
39
+
40
+ def callback_phase
41
+ @access_token = consumer.get_access_token(nil, {}, session['omniauth.xauth'])
42
+ super
43
+ rescue ::Net::HTTPFatalError => e
44
+ fail!(:service_unavailable, e)
45
+ rescue ::OAuth::Unauthorized => e
46
+ fail!(:invalid_credentials, e)
47
+ rescue ::MultiJson::DecodeError => e
48
+ fail!(:invalid_response, e)
49
+ ensure
50
+ session['omniauth.xauth'] = nil
51
+ end
52
+
53
+ def auth_hash
54
+ OmniAuth::Utils.deep_merge(super, {
55
+ 'credentials' => {
56
+ 'token' => @access_token.token,
57
+ 'secret' => @access_token.secret
58
+ }, 'extra' => {
59
+ 'access_token' => @access_token
60
+ }
61
+ })
62
+ end
63
+
64
+ end
65
+ end
66
+ end
67
+
@@ -56,8 +56,8 @@ module OmniAuth
56
56
  # TODO this is an easy patch to the underlying OAuth strategy a la OAuth2
57
57
  def request_phase
58
58
  request_token = consumer.get_request_token({:oauth_callback => callback_url}, {:scope => 'http://gdata.youtube.com'})
59
-
60
- (session['oauth']||={})[name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
59
+ session['oauth'] ||= {}
60
+ session['oauth'][name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
61
61
  r = Rack::Response.new
62
62
 
63
63
  if request_token.callback_confirmed?
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-oauth
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 0.2.0.beta5
4
+ prerelease:
5
+ version: 0.2.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Michael Bleigh
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-03-01 00:00:00 -06:00
13
+ date: 2011-03-11 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - "="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.2.0.beta5
23
+ version: 0.2.0
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: *id001
@@ -134,6 +134,17 @@ dependencies:
134
134
  type: :development
135
135
  prerelease: false
136
136
  version_requirements: *id011
137
+ - !ruby/object:Gem::Dependency
138
+ name: evernote
139
+ requirement: &id012 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ~>
143
+ - !ruby/object:Gem::Version
144
+ version: 0.9.0
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: *id012
137
148
  description: OAuth strategies for OmniAuth.
138
149
  email: michael@intridea.com
139
150
  executables: []
@@ -146,7 +157,10 @@ files:
146
157
  - lib/oa-oauth.rb
147
158
  - lib/omniauth/oauth.rb
148
159
  - lib/omniauth/strategies/bitly.rb
160
+ - lib/omniauth/strategies/dailymile.rb
161
+ - lib/omniauth/strategies/doit.rb
149
162
  - lib/omniauth/strategies/dopplr.rb
163
+ - lib/omniauth/strategies/evernote.rb
150
164
  - lib/omniauth/strategies/facebook.rb
151
165
  - lib/omniauth/strategies/foursquare.rb
152
166
  - lib/omniauth/strategies/github.rb
@@ -155,19 +169,24 @@ files:
155
169
  - lib/omniauth/strategies/gowalla.rb
156
170
  - lib/omniauth/strategies/hyves.rb
157
171
  - lib/omniauth/strategies/identica.rb
172
+ - lib/omniauth/strategies/instagram.rb
173
+ - lib/omniauth/strategies/instapaper.rb
158
174
  - lib/omniauth/strategies/linked_in.rb
159
175
  - lib/omniauth/strategies/meetup.rb
160
176
  - lib/omniauth/strategies/miso.rb
177
+ - lib/omniauth/strategies/mixi.rb
161
178
  - lib/omniauth/strategies/netflix.rb
162
179
  - lib/omniauth/strategies/oauth.rb
163
180
  - lib/omniauth/strategies/oauth2.rb
164
181
  - lib/omniauth/strategies/smug_mug.rb
165
182
  - lib/omniauth/strategies/sound_cloud.rb
166
183
  - lib/omniauth/strategies/thirty_seven_signals.rb
184
+ - lib/omniauth/strategies/trade_me.rb
167
185
  - lib/omniauth/strategies/trip_it.rb
168
186
  - lib/omniauth/strategies/twitter.rb
169
187
  - lib/omniauth/strategies/type_pad.rb
170
188
  - lib/omniauth/strategies/vimeo.rb
189
+ - lib/omniauth/strategies/xauth.rb
171
190
  - lib/omniauth/strategies/yahoo.rb
172
191
  - lib/omniauth/strategies/you_tube.rb
173
192
  - README.rdoc
@@ -186,16 +205,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
205
  requirements:
187
206
  - - ">="
188
207
  - !ruby/object:Gem::Version
189
- hash: -2581674124664783395
208
+ hash: -2125816653041836513
190
209
  segments:
191
210
  - 0
192
211
  version: "0"
193
212
  required_rubygems_version: !ruby/object:Gem::Requirement
194
213
  none: false
195
214
  requirements:
196
- - - ">"
215
+ - - ">="
197
216
  - !ruby/object:Gem::Version
198
- version: 1.3.1
217
+ hash: -2125816653041836513
218
+ segments:
219
+ - 0
220
+ version: "0"
199
221
  requirements: []
200
222
 
201
223
  rubyforge_project: