Everything can now be initialized with a block instead of arguments. Closes #56
This commit is contained in:
Родитель
4ec1060961
Коммит
c9f3375a18
|
@ -6,7 +6,7 @@ module OmniAuth
|
|||
class HttpBasic
|
||||
include OmniAuth::Strategy
|
||||
|
||||
def initialize(app, name, endpoint, headers = {})
|
||||
def initialize(app, name, endpoint = nil, headers = {}, &block)
|
||||
super
|
||||
@endpoint = endpoint
|
||||
@request_headers = headers
|
||||
|
|
|
@ -6,10 +6,10 @@ module OmniAuth
|
|||
class Password
|
||||
include OmniAuth::Strategy
|
||||
|
||||
def initialize(app, secret = 'changethisappsecret', options = {})
|
||||
def initialize(app, secret = 'changethisappsecret', options = {}, &block)
|
||||
@options = options
|
||||
@secret = secret
|
||||
super(app, :password)
|
||||
super(app, :password, &block)
|
||||
end
|
||||
|
||||
attr_reader :secret
|
||||
|
|
|
@ -11,10 +11,12 @@ module OmniAuth
|
|||
end
|
||||
end
|
||||
|
||||
def initialize(app, name, *args)
|
||||
def initialize(app, name, *args, &block)
|
||||
@app = app
|
||||
@name = name.to_sym
|
||||
@options = args.last.is_a?(Hash) ? args.pop : {}
|
||||
|
||||
yield self if block_given?
|
||||
end
|
||||
|
||||
def call(env)
|
||||
|
|
|
@ -29,7 +29,7 @@ Use the LDAP strategy as a middleware in your applicaiton:
|
|||
|
||||
require 'omniauth/enterprise'
|
||||
use OmniAuth::Strategies::LDAP,
|
||||
"My LDAP",
|
||||
:title => "My LDAP",
|
||||
:host => '10.101.10.1',
|
||||
:port => 389,
|
||||
:method => :plain,
|
||||
|
|
|
@ -8,8 +8,8 @@ module OmniAuth
|
|||
autoload :Configuration, 'omniauth/strategies/cas/configuration'
|
||||
autoload :ServiceTicketValidator, 'omniauth/strategies/cas/service_ticket_validator'
|
||||
|
||||
def initialize(app, options = {})
|
||||
super(app, options.delete(:name) || :cas, options)
|
||||
def initialize(app, options = {}, &block)
|
||||
super(app, options.delete(:name) || :cas, options, &block)
|
||||
@configuration = OmniAuth::Strategies::CAS::Configuration.new(options)
|
||||
end
|
||||
|
||||
|
|
|
@ -27,9 +27,8 @@ module OmniAuth
|
|||
#
|
||||
# @param [Rack Application] app Standard Rack middleware argument.
|
||||
# @option options [String, 'LDAP Authentication'] :title A title for the authentication form.
|
||||
def initialize(app, title, options = {})
|
||||
super(app, options[:name] || :ldap, options.dup)
|
||||
@title = title
|
||||
def initialize(app, options = {}, &block)
|
||||
super(app, options[:name] || :ldap, options.dup, &block)
|
||||
@name_proc = (@options.delete(:name_proc) || Proc.new {|name| name})
|
||||
@adaptor = OmniAuth::Strategies::LDAP::Adaptor.new(options)
|
||||
end
|
||||
|
|
|
@ -30,6 +30,6 @@ If you want to allow multiple providers, use the OmniAuth Builder:
|
|||
|
||||
use OmniAuth::Builder do
|
||||
provider :twitter, 'consumer_key', 'consumer_secret'
|
||||
provider :facebook, 'app_id', 'app_secret'
|
||||
provider :facebook, 'client_id', 'client_secret'
|
||||
end
|
||||
|
|
@ -13,7 +13,7 @@ module OmniAuth
|
|||
# Initialize the Dopplr strategy.
|
||||
#
|
||||
# @option options [Hash, {}] :client_options Options to be passed directly to the OAuth Consumer
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
client_options = {
|
||||
:site => 'https://www.dopplr.com',
|
||||
:request_token_path => "/oauth/request_token",
|
||||
|
@ -21,7 +21,7 @@ module OmniAuth
|
|||
:authorize_path => "/oauth/authorize"
|
||||
}
|
||||
|
||||
super(app, :dopplr, consumer_key, consumer_secret, client_options, options)
|
||||
super(app, :dopplr, consumer_key, consumer_secret, client_options, options, &block)
|
||||
end
|
||||
|
||||
def user_data
|
||||
|
|
|
@ -7,14 +7,14 @@ module OmniAuth
|
|||
# basic user information.
|
||||
#
|
||||
# @example Basic Usage
|
||||
# use OmniAuth::Strategies::Facebook, 'app_id', 'app_secret'
|
||||
# use OmniAuth::Strategies::Facebook, 'client_id', 'client_secret'
|
||||
class Facebook < OAuth2
|
||||
# @param [Rack Application] app standard middleware application parameter
|
||||
# @param [String] app_id the application id as [registered on Facebook](http://www.facebook.com/developers/)
|
||||
# @param [String] app_secret the application secret as registered on Facebook
|
||||
# @param [String] client_id the application id as [registered on Facebook](http://www.facebook.com/developers/)
|
||||
# @param [String] client_secret the application secret as registered on Facebook
|
||||
# @option options [String] :scope ('email,offline_access') comma-separated extended permissions such as `email` and `manage_pages`
|
||||
def initialize(app, app_id, app_secret, options = {})
|
||||
super(app, :facebook, app_id, app_secret, {:site => 'https://graph.facebook.com/'}, options)
|
||||
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
||||
super(app, :facebook, client_id, client_secret, {:site => 'https://graph.facebook.com/'}, options, &block)
|
||||
end
|
||||
|
||||
def user_data
|
||||
|
|
|
@ -8,7 +8,7 @@ module OmniAuth
|
|||
#
|
||||
# @option options [Boolean, true] :sign_in When true, use a sign-in flow instead of the authorization flow.
|
||||
# @option options [Boolean, false] :mobile When true, use the mobile sign-in interface.
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
client_options = {:site => 'http://foursquare.com'}
|
||||
|
||||
auth_path = (options[:sign_in] == false) ? '/oauth/authorize' : '/oauth/authenticate'
|
||||
|
@ -16,7 +16,7 @@ module OmniAuth
|
|||
|
||||
client_options[:authorize_path] = auth_path
|
||||
|
||||
super(app, :foursquare, consumer_key, consumer_secret, client_options, options)
|
||||
super(app, :foursquare, consumer_key, consumer_secret, client_options, options, &block)
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
|
|
|
@ -8,16 +8,16 @@ module OmniAuth
|
|||
# and provide the proper credentials to this middleware.
|
||||
class GitHub < OAuth2
|
||||
# @param [Rack Application] app standard middleware application argument
|
||||
# @param [String] app_id the application ID for your client
|
||||
# @param [String] app_secret the application secret
|
||||
def initialize(app, app_id, app_secret, options = {})
|
||||
# @param [String] client_id the application ID for your client
|
||||
# @param [String] client_secret the application secret
|
||||
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
||||
client_options = {
|
||||
:site => 'https://github.com/',
|
||||
:authorize_path => '/login/oauth/authorize',
|
||||
:access_token_path => '/login/oauth/access_token'
|
||||
}
|
||||
|
||||
super(app, :github, app_id, app_secret, client_options, options)
|
||||
super(app, :github, client_id, client_secret, client_options, options, &block)
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -14,14 +14,14 @@ module OmniAuth
|
|||
# @param [String] api_key the application id as [registered on Gowalla](http://gowalla.com/api/keys)
|
||||
# @param [String] secret_key the application secret as [registered on Gowalla](http://gowalla.com/api/keys)
|
||||
# @option options ['read','read-write'] :scope ('read') the scope of your authorization request; must be `read` or `read-write`
|
||||
def initialize(app, api_key, secret_key, options = {})
|
||||
def initialize(app, api_key = nil, secret_key = nil, options = {}, &block)
|
||||
client_options = {
|
||||
:site => 'https://api.gowalla.com/api/oauth',
|
||||
:authorize_url => 'https://gowalla.com/api/oauth/new',
|
||||
:access_token_url => 'https://api.gowalla.com/api/oauth/token'
|
||||
}
|
||||
|
||||
super(app, :gowalla, api_key, secret_key, client_options, options)
|
||||
super(app, :gowalla, api_key, secret_key, client_options, options, &block)
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -12,12 +12,12 @@ module OmniAuth
|
|||
# use OmniAuth::Strategies::Identica, 'consumerkey', 'consumersecret'
|
||||
#
|
||||
class Identica < OmniAuth::Strategies::OAuth
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
super(app, :identica, consumer_key, consumer_secret,
|
||||
{:site => 'http://identi.ca',
|
||||
:request_token_path => "/api/oauth/request_token",
|
||||
:access_token_path => "/api/oauth/access_token",
|
||||
:authorize_path => "/api/oauth/authorize"}, options)
|
||||
:authorize_path => "/api/oauth/authorize"}, options, &block)
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
|
|
|
@ -4,13 +4,13 @@ require 'omniauth/oauth'
|
|||
module OmniAuth
|
||||
module Strategies
|
||||
class LinkedIn < OmniAuth::Strategies::OAuth
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
super(app, :linked_in, consumer_key, consumer_secret,
|
||||
{:site => 'https://api.linkedin.com',
|
||||
:request_token_path => '/uas/oauth/requestToken',
|
||||
:access_token_path => '/uas/oauth/accessToken',
|
||||
:authorize_path => '/uas/oauth/authorize',
|
||||
:scheme => :header}, options)
|
||||
:scheme => :header}, options, &block)
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
|
|
|
@ -11,7 +11,7 @@ module OmniAuth
|
|||
# use OmniAuth::Strategies::Meetup, 'consumerkey', 'consumersecret'
|
||||
#
|
||||
class Meetup < OmniAuth::Strategies::OAuth
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
super(app, :meetup, consumer_key, consumer_secret,
|
||||
# :site => 'https://api.meetup.com',
|
||||
{:request_token_path => "https://api.meetup.com/oauth/request",
|
||||
|
|
|
@ -6,7 +6,9 @@ module OmniAuth
|
|||
class OAuth
|
||||
include OmniAuth::Strategy
|
||||
|
||||
def initialize(app, name, consumer_key, consumer_secret, consumer_options = {}, options = {})
|
||||
def initialize(app, name, consumer_key = nil, consumer_secret = nil, consumer_options = {}, options = {}, &block)
|
||||
self.consumer_key = consumer_key
|
||||
self.consumer_secret = consumer_secret
|
||||
self.consumer_options = consumer_options
|
||||
super
|
||||
end
|
||||
|
|
|
@ -16,7 +16,7 @@ module OmniAuth
|
|||
# The options passed in to the strategy.
|
||||
attr_accessor :options
|
||||
# The `OAuth2::Client` for this strategy.
|
||||
attr_accessor :client
|
||||
attr_accessor :client_id, :client_secret, :client_options
|
||||
|
||||
# An error that is indicated in the OAuth 2.0 callback.
|
||||
# This could be a `redirect_uri_mismatch` or other
|
||||
|
@ -37,9 +37,15 @@ module OmniAuth
|
|||
# @param [String] client_id the client/application ID of this provider
|
||||
# @param [String] client_secret the client/application secret of this provider
|
||||
# @param [Hash] options that will be passed through to the OAuth2::Client (see [oauth2 docs](http://rubydoc.info/gems/oauth2))
|
||||
def initialize(app, name, client_id, client_secret, client_options = {}, options = {})
|
||||
def initialize(app, name, client_id = nil, client_secret = nil, client_options = {}, options = {}, &block)
|
||||
self.client_id = client_id
|
||||
self.client_secret = client_secret
|
||||
self.client_options = client_options
|
||||
super
|
||||
self.client = ::OAuth2::Client.new(client_id, client_secret, client_options.merge(options[:client_options] || {}))
|
||||
end
|
||||
|
||||
def client
|
||||
::OAuth2::Client.new(client_id, client_secret, client_options.merge(options[:client_options] || {}))
|
||||
end
|
||||
|
||||
protected
|
||||
|
|
|
@ -9,12 +9,12 @@ module OmniAuth
|
|||
# use OmniAuth::Strategies::SmugMug, 'consumerkey', 'consumersecret'
|
||||
#
|
||||
class SmugMug < OmniAuth::Strategies::OAuth
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
super(app, :smugmug, consumer_key, consumer_secret,
|
||||
{:site => 'http://api.smugmug.com',
|
||||
:request_token_path => "/services/oauth/getRequestToken.mg",
|
||||
:access_token_path => "/services/oauth/getAccessToken.mg",
|
||||
:authorize_path => "/services/oauth/authorize.mg"}, options)
|
||||
:authorize_path => "/services/oauth/authorize.mg"}, options, &block)
|
||||
end
|
||||
|
||||
def auth_hash
|
||||
|
|
|
@ -13,7 +13,7 @@ module OmniAuth
|
|||
#
|
||||
|
||||
class SoundCloud < OmniAuth::Strategies::OAuth
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
super(app, :soundcloud, consumer_key, consumer_secret, {:site => 'https://api.soundcloud.com'}, options)
|
||||
end
|
||||
|
||||
|
|
|
@ -4,14 +4,14 @@ require 'multi_json'
|
|||
module OmniAuth
|
||||
module Strategies
|
||||
class ThirtySevenSignals < OAuth2
|
||||
def initialize(app, app_id, app_secret, options = {})
|
||||
def initialize(app, client_id = nil, client_secret = nil, options = {}, &block)
|
||||
client_options = {
|
||||
:site => 'https://launchpad.37signals.com/',
|
||||
:authorize_path => '/authorization/new',
|
||||
:access_token_path => '/authorization/token'
|
||||
}
|
||||
|
||||
super(app, :thirty_seven_signals, app_id, app_secret, client_options, options)
|
||||
super(app, :thirty_seven_signals, client_id, client_secret, client_options, options, &block)
|
||||
end
|
||||
|
||||
def user_data
|
||||
|
|
|
@ -10,12 +10,12 @@ module OmniAuth
|
|||
# use OmniAuth::Strategies::TripIt, 'consumerkey', 'consumersecret'
|
||||
#
|
||||
class TripIt < OmniAuth::Strategies::OAuth
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
super(app, :tripit, consumer_key, consumer_secret,
|
||||
{:site => 'https://api.tripit.com',
|
||||
:request_token_path => "/oauth/request_token",
|
||||
:access_token_path => "/oauth/access_token",
|
||||
:authorize_url => "https://www.tripit.com/oauth/authorize"}, options)
|
||||
:authorize_url => "https://www.tripit.com/oauth/authorize"}, options, &block)
|
||||
end
|
||||
|
||||
def request_phase
|
||||
|
|
|
@ -15,7 +15,7 @@ module OmniAuth
|
|||
# Initialize the middleware
|
||||
#
|
||||
# @option options [Boolean, true] :sign_in When true, use the "Sign in with Twitter" flow instead of the authorization flow.
|
||||
def initialize(app, consumer_key, consumer_secret, options = {})
|
||||
def initialize(app, consumer_key = nil, consumer_secret = nil, options = {}, &block)
|
||||
client_options = {
|
||||
:site => 'https://api.twitter.com'
|
||||
}
|
||||
|
|
|
@ -2,6 +2,10 @@ shared_examples_for "an oauth strategy" do
|
|||
it 'should be initializable with only three arguments' do
|
||||
lambda{ strategy_class.new(lambda{|env| [200, {}, ['Hello World']]}, 'key', 'secret') }.should_not raise_error
|
||||
end
|
||||
|
||||
it 'should be initializable with a block' do
|
||||
lambda{ strategy_class.new(lambda{|env| [200, {}, ['Hello World']]}){|s| s.consumer_key = 'abc'} }.should_not raise_error
|
||||
end
|
||||
|
||||
it 'should handle the setting of client options' do
|
||||
s = strategy_class.new(lambda{|env| [200, {}, ['Hello World']]}, 'key', 'secret', :client_options => {:abc => 'def'})
|
||||
|
@ -13,6 +17,10 @@ shared_examples_for "an oauth2 strategy" do
|
|||
it 'should be initializable with only three arguments' do
|
||||
lambda{ strategy_class.new(lambda{|env| [200, {}, ['Hello World']]}, 'key', 'secret') }.should_not raise_error
|
||||
end
|
||||
|
||||
it 'should be initializable with a block' do
|
||||
lambda{ strategy_class.new(lambda{|env| [200, {}, ['Hello World']]}){|s| s.client_id = 'abc'} }.should_not raise_error
|
||||
end
|
||||
|
||||
it 'should handle the setting of client options' do
|
||||
s = strategy_class.new(lambda{|env| [200, {}, ['Hello World']]}, 'key', 'secret', :client_options => {:abc => 'def'})
|
||||
|
|
|
@ -3,9 +3,9 @@ require 'omniauth/openid'
|
|||
module OmniAuth
|
||||
module Strategies
|
||||
class GoogleApps < OmniAuth::Strategies::OpenID
|
||||
def initialize(app, store = nil, options = {})
|
||||
def initialize(app, store = nil, options = {}, &block)
|
||||
options[:name] ||= 'google_apps'
|
||||
super(app, store, options)
|
||||
super(app, store, options, &block)
|
||||
end
|
||||
|
||||
def get_identifier
|
||||
|
|
|
@ -35,8 +35,8 @@ module OmniAuth
|
|||
# @option options [Array] :optional The optional attributes for the OpenID request. May
|
||||
# be ActiveExchange or sreg.
|
||||
# @option options [Symbol, :open_id] :name The URL segment name for this provider.
|
||||
def initialize(app, store = nil, options = {})
|
||||
super(app, options[:name] || :open_id)
|
||||
def initialize(app, store = nil, options = {}, &block)
|
||||
super(app, (options[:name] || :open_id), &block)
|
||||
@options = options
|
||||
@options[:required] ||= [AX[:email], AX[:name], AX[:first_name], AX[:last_name], 'email', 'fullname']
|
||||
@options[:optional] ||= [AX[:nickname], AX[:city], AX[:state], AX[:website], AX[:image], 'postcode', 'nickname']
|
||||
|
|
Загрузка…
Ссылка в новой задаче