oa-oauth 0.1.6 → 0.2.0.beta1

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.
@@ -30,6 +30,6 @@ If you want to allow multiple providers, use the OmniAuth Builder:
30
30
 
31
31
  use OmniAuth::Builder do
32
32
  provider :twitter, 'consumer_key', 'consumer_secret'
33
- provider :facebook, 'app_id', 'app_secret'
33
+ provider :facebook, 'client_id', 'client_secret'
34
34
  end
35
35
 
@@ -17,5 +17,6 @@ module OmniAuth
17
17
  autoload :Dopplr, 'omniauth/strategies/dopplr'
18
18
  autoload :Meetup, 'omniauth/strategies/meetup'
19
19
  autoload :SoundCloud, 'omniauth/strategies/sound_cloud'
20
+ autoload :SmugMug, 'omniauth/strategies/smug_mug'
20
21
  end
21
22
  end
@@ -10,13 +10,43 @@ module OmniAuth
10
10
  # use OmniAuth::Strategies::Dopplr, 'consumerkey', 'consumersecret'
11
11
  #
12
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
13
+ # Initialize the Dopplr strategy.
14
+ #
15
+ # @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ client_options = {
18
+ :site => 'https://www.dopplr.com',
19
+ :request_token_path => "/oauth/request_token",
20
+ :access_token_path => "/oauth/access_token",
21
+ :authorize_path => "/oauth/authorize"
22
+ }
23
+
24
+ super(app, :dopplr, consumer_key, consumer_secret, client_options, options, &block)
25
+ end
26
+
27
+ def user_data
28
+ @data ||= MultiJson.decode(@access_token.get('/oauthapi/whoami').body)['whoami']
29
+ end
30
+
31
+ def user_info
32
+ {
33
+ 'nickname' => user_data["nick"],
34
+ 'first_name' => user_data["forename"],
35
+ 'last_name' => user_data["surname"],
36
+ 'name' => "#{user_data['forename']} #{user_data['surname']}",
37
+ 'urls' => {
38
+ 'Dopplr' => user_data["dopplr_url"],
39
+ 'DopplrMobile' => user_data["mobile_url"],
40
+ }
41
+ }
42
+ end
43
+
44
+ def auth_hash
45
+ OmniAuth::Utils.deep_merge(super, {
46
+ 'uid' => user_data['nick'],
47
+ 'user_info' => user_info
48
+ })
49
+ end
20
50
  end
21
51
  end
22
52
  end
@@ -7,15 +7,14 @@ module OmniAuth
7
7
  # basic user information.
8
8
  #
9
9
  # @example Basic Usage
10
- # use OmniAuth::Strategies::Facebook, 'app_id', 'app_secret'
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] 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
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, app_id, app_secret, options = {})
17
- options[:site] = 'https://graph.facebook.com/'
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
@@ -30,9 +29,11 @@ module OmniAuth
30
29
  def user_info
31
30
  {
32
31
  'nickname' => user_data["link"].split('/').last,
32
+ 'email' => (user_data["email"] if user_data["email"]),
33
33
  'first_name' => user_data["first_name"],
34
34
  'last_name' => user_data["last_name"],
35
35
  'name' => "#{user_data['first_name']} #{user_data['last_name']}",
36
+ 'image' => "http://graph.facebook.com/#{user_data['id']}/picture?type=square",
36
37
  'urls' => {
37
38
  'Facebook' => user_data["link"],
38
39
  'Website' => user_data["website"],
@@ -1,9 +1,22 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
1
4
  module OmniAuth
2
5
  module Strategies
3
6
  class Foursquare < OAuth
4
- def initialize(app, consumer_key, consumer_secret)
5
- super(app, :foursquare, consumer_key, consumer_secret,
6
- :site => 'http://foursquare.com')
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, 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)
7
20
  end
8
21
 
9
22
  def auth_hash
@@ -8,13 +8,16 @@ module OmniAuth
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] app_id the application ID for your client
12
- # @param [String] app_secret the application secret
13
- def initialize(app, app_id, app_secret, options = {})
14
- options[:site] = 'https://github.com/'
15
- options[:authorize_path] = '/login/oauth/authorize'
16
- options[:access_token_path] = '/login/oauth/access_token'
17
- super(app, :github, app_id, app_secret, options)
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
@@ -14,11 +14,14 @@ 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
- options[:site] = 'https://api.gowalla.com/api/oauth'
19
- options[:authorize_url] = 'https://gowalla.com/api/oauth/new'
20
- options[:access_token_url] = 'https://api.gowalla.com/api/oauth/token'
21
- super(app, :gowalla, api_key, secret_key, options)
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
@@ -12,17 +12,17 @@ module OmniAuth
12
12
  # use OmniAuth::Strategies::Identica, 'consumerkey', 'consumersecret'
13
13
  #
14
14
  class Identica < OmniAuth::Strategies::OAuth
15
- def initialize(app, consumer_key, consumer_secret)
15
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
16
16
  super(app, :identica, consumer_key, consumer_secret,
17
- :site => 'http://identi.ca',
17
+ {:site => 'http://identi.ca',
18
18
  :request_token_path => "/api/oauth/request_token",
19
19
  :access_token_path => "/api/oauth/access_token",
20
- :authorize_path => "/api/oauth/authorize")
20
+ :authorize_path => "/api/oauth/authorize"}, options, &block)
21
21
  end
22
22
 
23
23
  def auth_hash
24
24
  OmniAuth::Utils.deep_merge(super, {
25
- 'uid' => @access_token.params[:user_id],
25
+ 'uid' => user_hash['id'],
26
26
  'user_info' => user_info,
27
27
  'extra' => {'user_hash' => user_hash}
28
28
  })
@@ -4,13 +4,13 @@ require 'omniauth/oauth'
4
4
  module OmniAuth
5
5
  module Strategies
6
6
  class LinkedIn < OmniAuth::Strategies::OAuth
7
- def initialize(app, consumer_key, consumer_secret)
7
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
8
8
  super(app, :linked_in, consumer_key, consumer_secret,
9
- :site => 'https://api.linkedin.com',
9
+ {:site => 'https://api.linkedin.com',
10
10
  :request_token_path => '/uas/oauth/requestToken',
11
11
  :access_token_path => '/uas/oauth/accessToken',
12
12
  :authorize_path => '/uas/oauth/authorize',
13
- :scheme => :header)
13
+ :scheme => :header}, options, &block)
14
14
  end
15
15
 
16
16
  def auth_hash
@@ -23,7 +23,7 @@ module OmniAuth
23
23
  end
24
24
 
25
25
  def user_hash(access_token)
26
- person = Nokogiri::XML::Document.parse(@access_token.get('/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location)').body).xpath('person')
26
+ person = Nokogiri::XML::Document.parse(@access_token.get('/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url)').body).xpath('person')
27
27
 
28
28
  hash = {
29
29
  'id' => person.xpath('id').text,
@@ -38,7 +38,9 @@ module OmniAuth
38
38
  end
39
39
  }
40
40
 
41
- hash[:name] = "#{hash['first_name']} #{hash['last_name']}"
41
+ hash['urls']['LinkedIn'] = person.xpath('public-profile-url').text
42
+ hash['name'] = "#{hash['first_name']} #{hash['last_name']}"
43
+
42
44
  hash
43
45
  end
44
46
  end
@@ -11,12 +11,12 @@ module OmniAuth
11
11
  # use OmniAuth::Strategies::Meetup, 'consumerkey', 'consumersecret'
12
12
  #
13
13
  class Meetup < OmniAuth::Strategies::OAuth
14
- def initialize(app, consumer_key, consumer_secret)
14
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
15
15
  super(app, :meetup, consumer_key, consumer_secret,
16
16
  # :site => 'https://api.meetup.com',
17
- :request_token_path => "https://api.meetup.com/oauth/request",
17
+ {:request_token_path => "https://api.meetup.com/oauth/request",
18
18
  :access_token_path => "https://api.meetup.com/oauth/access",
19
- :authorize_path => "http://www.meetup.com/authorize/")
19
+ :authorize_path => "http://www.meetup.com/authorize/"}, options)
20
20
  end
21
21
  end
22
22
  end
@@ -6,23 +6,40 @@ module OmniAuth
6
6
  class OAuth
7
7
  include OmniAuth::Strategy
8
8
 
9
- def initialize(app, name, consumer_key, consumer_secret, options = {})
9
+ def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block)
10
+ self.consumer_key = consumer_key
11
+ self.consumer_secret = consumer_secret
12
+ self.consumer_options = consumer_options
10
13
  super
11
- @consumer = ::OAuth::Consumer.new(consumer_key, consumer_secret, options)
12
14
  end
13
- attr_reader :name, :consumer
14
-
15
+
16
+ def consumer
17
+ ::OAuth::Consumer.new(consumer_key, consumer_secret, consumer_options.merge(options[:client_options] || options[:consumer_options] || {}))
18
+ end
19
+
20
+ attr_reader :name
21
+ attr_accessor :consumer_key, :consumer_secret, :consumer_options
22
+
15
23
  def request_phase
16
24
  request_token = consumer.get_request_token(:oauth_callback => callback_url)
17
25
  (session[:oauth]||={})[name.to_sym] = {:callback_confirmed => request_token.callback_confirmed?, :request_token => request_token.token, :request_secret => request_token.secret}
18
26
  r = Rack::Response.new
19
- r.redirect request_token.authorize_url
27
+
28
+ if request_token.callback_confirmed?
29
+ r.redirect(request_token.authorize_url)
30
+ else
31
+ r.redirect(request_token.authorize_url(:oauth_callback => callback_url))
32
+ end
33
+
20
34
  r.finish
21
35
  end
22
36
 
23
37
  def callback_phase
24
38
  request_token = ::OAuth::RequestToken.new(consumer, session[:oauth][name.to_sym].delete(:request_token), session[:oauth][name.to_sym].delete(:request_secret))
25
- @access_token = request_token.get_access_token(:oauth_verifier => request.params['oauth_verifier'])
39
+
40
+ opts = {}
41
+ opts[:oauth_callback] = callback_url if session[:oauth][:callback_confirmed]
42
+ @access_token = request_token.get_access_token(opts)
26
43
  super
27
44
  rescue ::OAuth::Unauthorized => e
28
45
  fail!(:invalid_credentials, e)
@@ -16,7 +16,7 @@ module OmniAuth
16
16
  # The options passed in to the strategy.
17
17
  attr_accessor :options
18
18
  # The `OAuth2::Client` for this strategy.
19
- attr_accessor :client
19
+ attr_accessor :client_id, :client_secret, :client_options
20
20
 
21
21
  # An error that is indicated in the OAuth 2.0 callback.
22
22
  # This could be a `redirect_uri_mismatch` or other
@@ -37,10 +37,15 @@ module OmniAuth
37
37
  # @param [String] client_id the client/application ID of this provider
38
38
  # @param [String] client_secret the client/application secret of this provider
39
39
  # @param [Hash] options that will be passed through to the OAuth2::Client (see [oauth2 docs](http://rubydoc.info/gems/oauth2))
40
- def initialize(app, name, client_id, client_secret, options = {})
41
- super(app, name)
42
- self.options = options
43
- self.client = ::OAuth2::Client.new(client_id, client_secret, options)
40
+ def initialize(app, name, client_id = nil, client_secret = nil, client_options = {}, options = {}, &block)
41
+ self.client_id = client_id
42
+ self.client_secret = client_secret
43
+ self.client_options = client_options
44
+ super
45
+ end
46
+
47
+ def client
48
+ ::OAuth2::Client.new(client_id, client_secret, client_options.merge(options[:client_options] || {}))
44
49
  end
45
50
 
46
51
  protected
@@ -0,0 +1,42 @@
1
+ require 'omniauth/oauth'
2
+ require 'multi_json'
3
+
4
+ module OmniAuth
5
+ module Strategies
6
+ #
7
+ # Authenticate to SmugMug via OAuth and retrieve basic user information.
8
+ # Usage:
9
+ # use OmniAuth::Strategies::SmugMug, 'consumerkey', 'consumersecret'
10
+ #
11
+ class SmugMug < OmniAuth::Strategies::OAuth
12
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
13
+ super(app, :smugmug, consumer_key, consumer_secret,
14
+ {:site => 'http://api.smugmug.com',
15
+ :request_token_path => "/services/oauth/getRequestToken.mg",
16
+ :access_token_path => "/services/oauth/getAccessToken.mg",
17
+ :authorize_path => "/services/oauth/authorize.mg"}, options, &block)
18
+ end
19
+
20
+ def auth_hash
21
+ OmniAuth::Utils.deep_merge(super, {
22
+ 'uid' => user_hash['id'],
23
+ 'user_info' => user_info,
24
+ 'extra' => { 'user_hash' => user_hash }
25
+ })
26
+ end
27
+
28
+ # user info according to schema
29
+ def user_info
30
+ {
31
+ 'nickname' => user_hash['NickName'],
32
+ 'name' => user_hash['NickName']
33
+ }
34
+ end
35
+
36
+ # info as supplied by SmugMug
37
+ def user_hash
38
+ @user_hash ||= MultiJson.decode(@access_token.get('/services/api/json/1.2.2/?method=smugmug.auth.checkAccessToken').body)['Auth']['User']
39
+ end
40
+ end
41
+ end
42
+ end
@@ -13,8 +13,8 @@ module OmniAuth
13
13
  #
14
14
 
15
15
  class SoundCloud < OmniAuth::Strategies::OAuth
16
- def initialize(app, consumer_key, consumer_secret)
17
- super(app, :soundcloud, consumer_key, consumer_secret, :site => 'https://api.soundcloud.com')
16
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
17
+ super(app, :soundcloud, consumer_key, consumer_secret, {:site => 'https://api.soundcloud.com'}, options)
18
18
  end
19
19
 
20
20
  def auth_hash
@@ -4,11 +4,14 @@ require 'multi_json'
4
4
  module OmniAuth
5
5
  module Strategies
6
6
  class ThirtySevenSignals < OAuth2
7
- def initialize(app, app_id, app_secret, options = {})
8
- options[:site] = 'https://launchpad.37signals.com/'
9
- options[:authorize_path] = '/authorization/new'
10
- options[:access_token_path] = '/authorization/token'
11
- super(app, :thirty_seven_signals, app_id, app_secret, options)
7
+ def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
8
+ client_options = {
9
+ :site => 'https://launchpad.37signals.com/',
10
+ :authorize_path => '/authorization/new',
11
+ :access_token_path => '/authorization/token'
12
+ }
13
+
14
+ super(app, :thirty_seven_signals, client_id, client_secret, client_options, options, &block)
12
15
  end
13
16
 
14
17
  def user_data
@@ -10,12 +10,12 @@ module OmniAuth
10
10
  # use OmniAuth::Strategies::TripIt, 'consumerkey', 'consumersecret'
11
11
  #
12
12
  class TripIt < OmniAuth::Strategies::OAuth
13
- def initialize(app, consumer_key, consumer_secret)
13
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
14
14
  super(app, :tripit, consumer_key, consumer_secret,
15
- :site => 'https://api.tripit.com',
15
+ {:site => 'https://api.tripit.com',
16
16
  :request_token_path => "/oauth/request_token",
17
17
  :access_token_path => "/oauth/access_token",
18
- :authorize_url => "https://www.tripit.com/oauth/authorize")
18
+ :authorize_url => "https://www.tripit.com/oauth/authorize"}, options, &block)
19
19
  end
20
20
 
21
21
  def request_phase
@@ -12,10 +12,16 @@ module OmniAuth
12
12
  # use OmniAuth::Strategies::Twitter, 'consumerkey', 'consumersecret'
13
13
  #
14
14
  class Twitter < OmniAuth::Strategies::OAuth
15
- def initialize(app, consumer_key, consumer_secret)
16
- super(app, :twitter, consumer_key, consumer_secret,
17
- :site => 'https://api.twitter.com',
18
- :authorize_path => '/oauth/authenticate')
15
+ # Initialize the middleware
16
+ #
17
+ # @option options [Boolean, true] :sign_in When true, use the "Sign in with Twitter" flow instead of the authorization flow.
18
+ def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
19
+ client_options = {
20
+ :site => 'https://api.twitter.com'
21
+ }
22
+
23
+ client_options[:authorize_path] = '/oauth/authenticate' unless options[:sign_in] == false
24
+ super(app, :twitter, consumer_key, consumer_secret, client_options, options)
19
25
  end
20
26
 
21
27
  def auth_hash
@@ -35,7 +41,10 @@ module OmniAuth
35
41
  'location' => user_hash['location'],
36
42
  'image' => user_hash['profile_image_url'],
37
43
  'description' => user_hash['description'],
38
- 'urls' => {'Website' => user_hash['url']}
44
+ 'urls' => {
45
+ 'Website' => user_hash['url'],
46
+ 'Twitter' => 'http://twitter.com/' + user_hash['screen_name']
47
+ }
39
48
  }
40
49
  end
41
50
 
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oa-oauth
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: -1848230051
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 6
10
- version: 0.1.6
8
+ - 2
9
+ - 0
10
+ - beta1
11
+ version: 0.2.0.beta1
11
12
  platform: ruby
12
13
  authors:
13
14
  - Michael Bleigh
@@ -15,7 +16,7 @@ autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2010-10-25 00:00:00 -05:00
19
+ date: 2010-11-29 00:00:00 -06:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -24,12 +25,13 @@ dependencies:
24
25
  requirements:
25
26
  - - "="
26
27
  - !ruby/object:Gem::Version
27
- hash: 23
28
+ hash: -1848230051
28
29
  segments:
29
30
  - 0
30
- - 1
31
- - 6
32
- version: 0.1.6
31
+ - 2
32
+ - 0
33
+ - beta1
34
+ version: 0.2.0.beta1
33
35
  requirement: *id001
34
36
  name: oa-core
35
37
  prerelease: false
@@ -212,6 +214,7 @@ files:
212
214
  - lib/omniauth/strategies/meetup.rb
213
215
  - lib/omniauth/strategies/oauth.rb
214
216
  - lib/omniauth/strategies/oauth2.rb
217
+ - lib/omniauth/strategies/smug_mug.rb
215
218
  - lib/omniauth/strategies/sound_cloud.rb
216
219
  - lib/omniauth/strategies/thirty_seven_signals.rb
217
220
  - lib/omniauth/strategies/trip_it.rb
@@ -240,12 +243,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
240
243
  required_rubygems_version: !ruby/object:Gem::Requirement
241
244
  none: false
242
245
  requirements:
243
- - - ">="
246
+ - - ">"
244
247
  - !ruby/object:Gem::Version
245
- hash: 3
248
+ hash: 25
246
249
  segments:
247
- - 0
248
- version: "0"
250
+ - 1
251
+ - 3
252
+ - 1
253
+ version: 1.3.1
249
254
  requirements: []
250
255
 
251
256
  rubyforge_project: