oa-oauth 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,5 +13,7 @@ module OmniAuth
13
13
  autoload :Foursquare, 'omniauth/strategies/foursquare'
14
14
  autoload :Gowalla, 'omniauth/strategies/gowalla'
15
15
  autoload :Identica, 'omniauth/strategies/identica'
16
+ autoload :TripIt, 'omniauth/strategies/trip_it'
17
+ autoload :Dopplr, 'omniauth/strategies/dopplr'
16
18
  end
17
19
  end
@@ -0,0 +1,22 @@
1
+ require 'omniauth/oauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ #
6
+ # Authenticate to Dopplr via OAuth and retrieve an access token for API usage
7
+ #
8
+ # Usage:
9
+ #
10
+ # use OmniAuth::Strategies::Dopplr, 'consumerkey', 'consumersecret'
11
+ #
12
+ class Dopplr < OmniAuth::Strategies::OAuth
13
+ def initialize(app, consumer_key, consumer_secret)
14
+ super(app, :dopplr, consumer_key, consumer_secret,
15
+ :site => 'https://www.dopplr.com',
16
+ :request_token_path => "/oauth/request_token",
17
+ :access_token_path => "/oauth/access_token",
18
+ :authorize_path => "/oauth/authorize")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,25 +3,23 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
- #
7
6
  # Authenticate to Facebook utilizing OAuth 2.0 and retrieve
8
7
  # basic user information.
9
8
  #
10
- # Usage:
11
- #
12
- # use OmniAuth::Strategies::Facebook, 'app_id', 'app_secret'
13
- #
14
- # Options:
15
- #
16
- # <tt>:scope</tt> :: Extended permissions such as <tt>email</tt> and <tt>offline_access</tt> (which are the defaults).
9
+ # @example Basic Usage
10
+ # use OmniAuth::Strategies::Facebook, 'app_id', 'app_secret'
17
11
  class Facebook < OAuth2
12
+ # @param [Rack Application] app standard middleware application parameter
13
+ # @param [String] app_id the application id as [registered on Facebook](http://www.facebook.com/developers/)
14
+ # @param [String] app_secret the application secret as registered on Facebook
15
+ # @option options [String] :scope ('email,offline_access') comma-separated extended permissions such as `email` and `manage_pages`
18
16
  def initialize(app, app_id, app_secret, options = {})
19
17
  options[:site] = 'https://graph.facebook.com/'
20
18
  super(app, :facebook, app_id, app_secret, options)
21
19
  end
22
20
 
23
21
  def user_data
24
- @data ||= MultiJson.decode(@access_token.get('/me'))
22
+ @data ||= MultiJson.decode(@access_token.get('/me', {}, { "Accept-Language" => "en-us,en;"}))
25
23
  end
26
24
 
27
25
  def request_phase
@@ -51,4 +49,4 @@ module OmniAuth
51
49
  end
52
50
  end
53
51
  end
54
- end
52
+ end
@@ -3,7 +3,13 @@ require 'multi_json'
3
3
 
4
4
  module OmniAuth
5
5
  module Strategies
6
+ # OAuth 2.0 based authentication with GitHub. In order to
7
+ # sign up for an application, you need to [register an application](http://github.com/account/applications/new)
8
+ # and provide the proper credentials to this middleware.
6
9
  class GitHub < OAuth2
10
+ # @param [Rack Application] app standard middleware application argument
11
+ # @param [String] app_id the application ID for your client
12
+ # @param [String] app_secret the application secret
7
13
  def initialize(app, app_id, app_secret, options = {})
8
14
  options[:site] = 'https://github.com/'
9
15
  options[:authorize_path] = '/login/oauth/authorize'
@@ -11,6 +17,8 @@ module OmniAuth
11
17
  super(app, :github, app_id, app_secret, options)
12
18
  end
13
19
 
20
+ protected
21
+
14
22
  def user_data
15
23
  @data ||= MultiJson.decode(@access_token.get('/api/v2/json/user/show'))['user']
16
24
  end
@@ -0,0 +1,3 @@
1
+ module OmniAuth
2
+ module Strategies
3
+ class GoogleAppsMarket
@@ -7,14 +7,13 @@ module OmniAuth
7
7
  # Authenticate to Gowalla utilizing OAuth 2.0 and retrieve
8
8
  # basic user information.
9
9
  #
10
- # Usage:
11
- #
12
- # use OmniAuth::Strategies::Gowalla, 'API Key', 'Secret Key'
13
- #
14
- # Options:
15
- #
16
- # <tt>:scope</tt> :: Extended permissions such as <tt>email</tt> and <tt>offline_access</tt> (which are the defaults).
10
+ # @example Basic Usage
11
+ # use OmniAuth::Strategies::Gowalla, 'API Key', 'Secret Key'
17
12
  class Gowalla < OAuth2
13
+ # @param [Rack Application] app standard middleware application parameter
14
+ # @param [String] api_key the application id as [registered on Gowalla](http://gowalla.com/api/keys)
15
+ # @param [String] secret_key the application secret as [registered on Gowalla](http://gowalla.com/api/keys)
16
+ # @option options ['read','read-write'] :scope ('read') the scope of your authorization request; must be `read` or `read-write`
18
17
  def initialize(app, api_key, secret_key, options = {})
19
18
  options[:site] = 'https://api.gowalla.com/api/oauth'
20
19
  options[:authorize_url] = 'https://gowalla.com/api/oauth/new'
@@ -22,12 +21,14 @@ module OmniAuth
22
21
  super(app, :gowalla, api_key, secret_key, options)
23
22
  end
24
23
 
24
+ protected
25
+
25
26
  def user_data
26
27
  @data ||= MultiJson.decode(@access_token.get("/users/me.json"))
27
28
  end
28
29
 
29
30
  def request_phase
30
- options[:scope] ||= "email,offline_access"
31
+ options[:scope] ||= "read"
31
32
  super
32
33
  end
33
34
 
@@ -5,11 +5,21 @@ require 'omniauth/oauth'
5
5
 
6
6
  module OmniAuth
7
7
  module Strategies
8
+ # Authentication strategy for connecting with APIs constructed using
9
+ # the [OAuth 2.0 Specification](http://tools.ietf.org/html/draft-ietf-oauth-v2-10).
10
+ # You must generally register your application with the provider and
11
+ # utilize an application id and secret in order to authenticate using
12
+ # OAuth 2.0.
8
13
  class OAuth2
9
14
  include OmniAuth::Strategy
10
15
 
11
- attr_accessor :options, :client
16
+ # The options passed in to the strategy.
17
+ attr_accessor :options
18
+ # The `OAuth2::Client` for this strategy.
19
+ attr_accessor :client
12
20
 
21
+ # An error that is indicated in the OAuth 2.0 callback.
22
+ # This could be a `redirect_uri_mismatch` or other
13
23
  class CallbackError < StandardError
14
24
  attr_accessor :error, :error_reason, :error_uri
15
25
 
@@ -20,6 +30,13 @@ module OmniAuth
20
30
  end
21
31
  end
22
32
 
33
+ # Initialize a new OAuth 2.0 authentication provider.
34
+
35
+ # @param [Rack Application] app standard middleware application argument
36
+ # @param [String] name the name for this provider to be used in its URL, e.g. `/auth/name`
37
+ # @param [String] client_id the client/application ID of this provider
38
+ # @param [String] client_secret the client/application secret of this provider
39
+ # @param [Hash] options that will be passed through to the OAuth2::Client (see [oauth2 docs](http://rubydoc.info/gems/oauth2))
23
40
  def initialize(app, name, client_id, client_secret, options = {})
24
41
  super(app, name)
25
42
  self.options = options
@@ -33,7 +50,7 @@ module OmniAuth
33
50
  end
34
51
 
35
52
  def callback_phase
36
- if request.params['error']
53
+ if request.params['error'] || request.params['error_reason']
37
54
  raise CallbackError.new(request.params['error'], request.params['error_description'] || request.params['error_reason'], request.params['error_uri'])
38
55
  end
39
56
 
@@ -0,0 +1,35 @@
1
+ require 'omniauth/oauth'
2
+
3
+ module OmniAuth
4
+ module Strategies
5
+ #
6
+ # Authenticate to TripIt via OAuth and retrieve an access token for API usage
7
+ #
8
+ # Usage:
9
+ #
10
+ # use OmniAuth::Strategies::TripIt, 'consumerkey', 'consumersecret'
11
+ #
12
+ class TripIt < OmniAuth::Strategies::OAuth
13
+ def initialize(app, consumer_key, consumer_secret)
14
+ super(app, :tripit, consumer_key, consumer_secret,
15
+ :site => 'https://api.tripit.com',
16
+ :request_token_path => "/oauth/request_token",
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) {|s| sprintf('%%%02x', s[0]) }
32
+ end
33
+ end
34
+ end
35
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-oauth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 4
10
- version: 0.1.4
9
+ - 5
10
+ version: 0.1.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Michael Bleigh
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-12 00:00:00 -05:00
18
+ date: 2010-10-19 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -24,12 +24,12 @@ dependencies:
24
24
  requirements:
25
25
  - - "="
26
26
  - !ruby/object:Gem::Version
27
- hash: 19
27
+ hash: 17
28
28
  segments:
29
29
  - 0
30
30
  - 1
31
- - 4
32
- version: 0.1.4
31
+ - 5
32
+ version: 0.1.5
33
33
  requirement: *id001
34
34
  name: oa-core
35
35
  prerelease: false
@@ -202,15 +202,18 @@ extra_rdoc_files: []
202
202
 
203
203
  files:
204
204
  - lib/omniauth/oauth.rb
205
+ - lib/omniauth/strategies/dopplr.rb
205
206
  - lib/omniauth/strategies/facebook.rb
206
207
  - lib/omniauth/strategies/foursquare.rb
207
208
  - lib/omniauth/strategies/github.rb
209
+ - lib/omniauth/strategies/google_apps_market.rb
208
210
  - lib/omniauth/strategies/gowalla.rb
209
211
  - lib/omniauth/strategies/identica.rb
210
212
  - lib/omniauth/strategies/linked_in.rb
211
213
  - lib/omniauth/strategies/oauth.rb
212
214
  - lib/omniauth/strategies/oauth2.rb
213
215
  - lib/omniauth/strategies/thirty_seven_signals.rb
216
+ - lib/omniauth/strategies/trip_it.rb
214
217
  - lib/omniauth/strategies/twitter.rb
215
218
  - README.rdoc
216
219
  - LICENSE.rdoc