Skip to content
Browse files

Don't automatically load the middleware. Instead, allow clients to lo…

…ad it as best fits them. Perform config when mounting the middleware.
  • Loading branch information...
1 parent 48119a4 commit 31e24eb328649e5eae32c85092eaaf9423e6e20c @cheald committed Feb 9, 2012
Showing with 12 additions and 11 deletions.
  1. +12 −7 README.rdoc
  2. +0 −1 lib/rack/oauth2/server/railtie.rb
  3. +0 −3 rails/init.rb
View
19 README.rdoc
@@ -30,19 +30,24 @@ support a different database engine, send us a pull request.
=== Step 2: Use The Server
-For Rails 2.3/3.0, Rack::OAuth2::Server automatically adds itself as middleware
-when required, but you do need to configure it from within
-+config/environment.rb+ (or one of the specific environment files). For example:
+For Rails 2.x, include the middleware as per usual from within +config/environment.rb+
+(or one of the specific environment files). Configuration is done on the Server.options struct.
+For example:
Rails::Initializer.run do |config|
. . .
- config.after_initialize do
- config.oauth.database = Mongo::Connection.new["my_db"]
- config.oauth.authenticator = lambda do |username, password|
+
+ config.middleware.use(::Rack::OAuth2::Server, ::Rack::OAuth2::Server.options.tap {|opt|
+ opt.logger = Rails.logger
+ opt.database = Mongo::Connection.new["my_db"]
+ opt.expires_in = 3600
+ opt.param_authentication = true
+ opt.authenticator = authenticator = lambda do |username, password|
user = User.find(username)
user.id if user && user.authenticated?(password)
end
- end
+ })
+
end
For Sinatra and Padrino, first require +rack/oauth2/sinatra+ and register
View
1 lib/rack/oauth2/server/railtie.rb
@@ -10,7 +10,6 @@ class Railtie < ::Rails::Railtie # :nodoc:
config.oauth = Server.options
initializer "rack-oauth2-server" do |app|
- app.middleware.use ::Rack::OAuth2::Server, app.config.oauth
config.oauth.logger ||= ::Rails.logger
class ::ActionController::Base
helper ::Rack::OAuth2::Rails::Helpers
View
3 rails/init.rb
@@ -1,9 +1,6 @@
# Rails 2.x initialization.
require "rack/oauth2/rails"
-config.extend ::Rack::OAuth2::Rails::Configuration
-config.oauth.logger ||= Rails.logger
-config.middleware.use ::Rack::OAuth2::Server, config.oauth
class ActionController::Base
helper ::Rack::OAuth2::Rails::Helpers
include ::Rack::OAuth2::Rails::Helpers

3 comments on commit 31e24eb

@cj
cj commented on 31e24eb Feb 9, 2012

Is there a reason you removed Rails 2.3/3.0 and replaced it with Rails 2.x ?

@cheald
Owner
cheald commented on 31e24eb Feb 9, 2012

I originally only modified the 2.x initializer, then went back and updated the 3.x railtie as well, but forgot to update the readme. :)

@cj
cj commented on 31e24eb Feb 9, 2012

ah :)

p.s. thank you for your updates.

Please sign in to comment.
Something went wrong with that request. Please try again.