oa-oauth 0.2.0.beta4 → 0.2.0.beta5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/oa-oauth.rb ADDED
@@ -0,0 +1 @@
1
+ require 'omniauth/oauth'
@@ -27,5 +27,6 @@ module OmniAuth
27
27
  autoload :Vimeo, 'omniauth/strategies/vimeo'
28
28
  autoload :YouTube, 'omniauth/strategies/you_tube'
29
29
  autoload :Hyves, 'omniauth/strategies/hyves'
30
+ autoload :Miso, 'omniauth/strategies/miso'
30
31
  end
31
32
  end
@@ -3,50 +3,55 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- class Foursquare < OAuth
6
+ class Foursquare < OAuth2
7
7
  # Initialize the middleware
8
8
  #
9
9
  # @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
10
10
  # @option options [Boolean, false] :mobile When true, use the mobile sign-in interface.
11
- def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
12
- client_options = {:site => 'http://foursquare.com'}
13
-
14
- auth_path = (options[:sign_in] == false) ? '/oauth/authorize' : '/oauth/authenticate'
15
- auth_path = "/mobile#{auth_path}" if options[:mobile]
16
-
17
- client_options[:authorize_path] = auth_path
18
-
19
- super(app, :foursquare, consumer_key, consumer_secret, client_options, options, &block)
11
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
12
+ super(app, :foursquare, client_id, client_secret, {
13
+ :site => "https://api.foursquare.com/v2",
14
+ :authorize_url => "https://foursquare.com/oauth2/authenticate",
15
+ :access_token_url => "https://foursquare.com/oauth2/access_token"
16
+ }, options, &block)
20
17
  end
21
18
 
22
- def auth_hash
23
- OmniAuth::Utils.deep_merge(super, {
24
- 'uid' => user_hash['id'],
25
- 'user_info' => user_info,
26
- 'extra' => {'user_hash' => user_hash}
27
- })
19
+ def user_data
20
+ @data ||= MultiJson.decode(@access_token.get(client.site+'/users/self', {'oauth_token' => @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
28
31
  end
29
32
 
30
33
  def user_info
31
- user_hash = self.user_hash
32
-
33
34
  {
34
- 'nickname' => user_hash['twitter'],
35
- 'first_name' => user_hash['firstname'],
36
- 'last_name' => user_hash['lastname'],
37
- 'email' => user_hash['email'],
38
- 'name' => "#{user_hash['firstname']} #{user_hash['lastname']}".strip,
39
- # 'location' => user_hash['location'],
40
- 'image' => user_hash['photo'],
41
- # 'description' => user_hash['description'],
42
- 'phone' => user_hash['phone'],
35
+ 'nickname' => user_data['response']['user']['contact']['twitter'],
36
+ 'first_name' => user_data['response']['user']['firstName'],
37
+ 'last_name' => user_data['response']['user']['lastName'],
38
+ 'email' => user_data['response']['user']['contact']['twitter'],
39
+ 'name' => "#{user_data['response']['user']['firstName']} #{user_data['response']['user']['lastName']}".strip,
40
+ # 'location' => user_data['response']['user']['location'],
41
+ 'image' => user_data['response']['user']['photo'],
42
+ # 'description' => user_data['response']['user']['description'],
43
+ 'phone' => user_data['response']['user']['contact']['phone'],
43
44
  'urls' => {}
44
45
  }
45
46
  end
46
47
 
47
- def user_hash
48
- @user_hash ||= MultiJson.decode(@access_token.get('http://api.foursquare.com/v1/user.json').body)['user']
48
+ def auth_hash
49
+ OmniAuth::Utils.deep_merge(super, {
50
+ 'uid' => user_data['response']['user']['id'],
51
+ 'user_info' => user_info,
52
+ 'extra' => {'user_hash' => user_data['response']['user']}
53
+ })
49
54
  end
50
55
  end
51
56
  end
52
- end
57
+ end
@@ -20,8 +20,10 @@ module OmniAuth
20
20
  :authorize_path => '/accounts/OAuthAuthorizeToken'
21
21
  }
22
22
 
23
- options[:scope] ||= "http://www.google.com/m8/feeds"
24
-
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
+
25
27
  super(app, :google, consumer_key, consumer_secret, client_options, options)
26
28
  end
27
29
 
@@ -5,12 +5,18 @@ module OmniAuth
5
5
  module Strategies
6
6
  class LinkedIn < OmniAuth::Strategies::OAuth
7
7
  def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
8
- super(app, :linked_in, consumer_key, consumer_secret,
9
- {:site => 'https://api.linkedin.com',
10
- :request_token_path => '/uas/oauth/requestToken',
11
- :access_token_path => '/uas/oauth/accessToken',
12
- :authorize_path => '/uas/oauth/authorize',
13
- :scheme => :header}, options, &block)
8
+ client_options = {
9
+ :site => 'https://api.linkedin.com',
10
+ :request_token_path => '/uas/oauth/requestToken',
11
+ :access_token_path => '/uas/oauth/accessToken',
12
+ :authorize_path => '/uas/oauth/authorize',
13
+ :scheme => :header
14
+ }
15
+
16
+ client_options[:authorize_path] = '/uas/oauth/authenticate' unless options[:sign_in] == false
17
+
18
+ '/uas/oauth/authorize'
19
+ super(app, :linked_in, consumer_key, consumer_secret, client_options, options, &block)
14
20
  end
15
21
 
16
22
  def auth_hash
@@ -0,0 +1,41 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to Miso via OAuth and retrieve basic
8
+ # user information.
9
+ #
10
+ # Usage:
11
+ #
12
+ # use OmniAuth::Strategies::Miso, 'consumerkey', 'consumersecret'
13
+ #
14
+ class Miso < OmniAuth::Strategies::OAuth
15
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
16
+ super(app, :miso, consumer_key, consumer_secret, {:site => 'https://gomiso.com'}, options)
17
+ end
18
+
19
+ def auth_hash
20
+ OmniAuth::Utils.deep_merge(super, {
21
+ 'uid' => user_hash['id'],
22
+ 'user_info' => user_info,
23
+ 'extra' => {'user_hash' => user_hash}
24
+ })
25
+ end
26
+
27
+ def user_info
28
+ {
29
+ 'nickname' => user_hash['username'],
30
+ 'name' => user_hash['full_name'],
31
+ 'image' => user_hash['profile_image_url'],
32
+ 'description' => user_hash['tagline'],
33
+ }
34
+ end
35
+
36
+ def user_hash
37
+ @user_hash ||= MultiJson.decode(@access_token.get('/api/oauth/v1/users/show.json').body)['user']
38
+ end
39
+ end
40
+ end
41
+ end
@@ -5,64 +5,66 @@ module OmniAuth
5
5
  module Strategies
6
6
  class OAuth
7
7
  include OmniAuth::Strategy
8
-
8
+
9
9
  def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block)
10
10
  self.consumer_key = consumer_key
11
11
  self.consumer_secret = consumer_secret
12
12
  self.consumer_options = consumer_options
13
13
  super
14
14
  end
15
-
15
+
16
16
  def consumer
17
17
  ::OAuth::Consumer.new(consumer_key, consumer_secret, consumer_options.merge(options[:client_options] || options[:consumer_options] || {}))
18
18
  end
19
19
 
20
20
  attr_reader :name
21
21
  attr_accessor :consumer_key, :consumer_secret, :consumer_options
22
-
22
+
23
23
  def request_phase
24
24
  request_token = consumer.get_request_token(:oauth_callback => callback_url)
25
25
  (session['oauth']||={})[name.to_s] = {'callback_confirmed' => request_token.callback_confirmed?, 'request_token' => request_token.token, 'request_secret' => request_token.secret}
26
26
  r = Rack::Response.new
27
-
27
+
28
28
  if request_token.callback_confirmed?
29
29
  r.redirect(request_token.authorize_url)
30
30
  else
31
- r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
31
+ r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
32
32
  end
33
-
33
+
34
34
  r.finish
35
35
  end
36
-
36
+
37
37
  def callback_phase
38
38
  request_token = ::OAuth::RequestToken.new(consumer, session['oauth'][name.to_s].delete('request_token'), session['oauth'][name.to_s].delete('request_secret'))
39
-
39
+
40
40
  opts = {}
41
41
  if session['oauth'][name.to_s]['callback_confirmed']
42
- opts[:oauth_verifier] = request['oauth_verifier']
42
+ opts[:oauth_verifier] = request['oauth_verifier']
43
43
  else
44
- opts[:oauth_callback] = callback_url
44
+ opts[:oauth_callback] = callback_url
45
45
  end
46
46
 
47
47
  @access_token = request_token.get_access_token(opts)
48
48
  super
49
+ rescue ::Net::HTTPFatalError => e
50
+ fail!(:service_unavailable, e)
49
51
  rescue ::OAuth::Unauthorized => e
50
52
  fail!(:invalid_credentials, e)
51
53
  rescue ::MultiJson::DecodeError => e
52
54
  fail!(:invalid_response, e)
53
55
  end
54
-
56
+
55
57
  def auth_hash
56
58
  OmniAuth::Utils.deep_merge(super, {
57
59
  'credentials' => {
58
- 'token' => @access_token.token,
60
+ 'token' => @access_token.token,
59
61
  'secret' => @access_token.secret
60
62
  }, 'extra' => {
61
63
  'access_token' => @access_token
62
64
  }
63
65
  })
64
66
  end
65
-
67
+
66
68
  def unique_id
67
69
  nil
68
70
  end
@@ -64,7 +64,7 @@ module OmniAuth
64
64
  end
65
65
 
66
66
  verifier = request.params['code']
67
- @access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
67
+ @access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
68
68
 
69
69
  if @access_token.expires? && @access_token.expires_in <= 0
70
70
  client.request(:post, client.access_token_url, {
@@ -72,8 +72,8 @@ module OmniAuth
72
72
  'grant_type' => 'refresh_token',
73
73
  'client_secret' => client_secret,
74
74
  'refresh_token' => @access_token.refresh_token
75
- })
76
- @access_token = client.web_server.get_access_token(verifier, :redirect_uri => callback_url)
75
+ }.merge(options))
76
+ @access_token = client.web_server.get_access_token(verifier, {:redirect_uri => callback_url}.merge(options))
77
77
  end
78
78
 
79
79
  super
@@ -17,19 +17,6 @@ module OmniAuth
17
17
  :access_token_path => "/oauth/access_token",
18
18
  :authorize_url => "https://www.tripit.com/oauth/authorize"}, options, &block)
19
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) }
32
- end
33
20
  end
34
21
  end
35
22
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: oa-oauth
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: 6
5
- version: 0.2.0.beta4
5
+ version: 0.2.0.beta5
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-02-11 00:00:00 -06:00
13
+ date: 2011-03-01 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.beta4
23
+ version: 0.2.0.beta5
24
24
  type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: *id001
@@ -143,6 +143,7 @@ extensions: []
143
143
  extra_rdoc_files: []
144
144
 
145
145
  files:
146
+ - lib/oa-oauth.rb
146
147
  - lib/omniauth/oauth.rb
147
148
  - lib/omniauth/strategies/bitly.rb
148
149
  - lib/omniauth/strategies/dopplr.rb
@@ -156,6 +157,7 @@ files:
156
157
  - lib/omniauth/strategies/identica.rb
157
158
  - lib/omniauth/strategies/linked_in.rb
158
159
  - lib/omniauth/strategies/meetup.rb
160
+ - lib/omniauth/strategies/miso.rb
159
161
  - lib/omniauth/strategies/netflix.rb
160
162
  - lib/omniauth/strategies/oauth.rb
161
163
  - lib/omniauth/strategies/oauth2.rb
@@ -184,7 +186,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
184
186
  requirements:
185
187
  - - ">="
186
188
  - !ruby/object:Gem::Version
187
- hash: 3188666288228867303
189
+ hash: -2581674124664783395
188
190
  segments:
189
191
  - 0
190
192
  version: "0"