Skip to content

Commit

Permalink
implement authenticate interface to change auth middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
machu committed Jun 2, 2013
1 parent 41b7eac commit 88c63b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion tdiary/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def call( env )
end

map Application.config.path[:update] do
use TDiary::Rack::Auth::Basic, '.htpasswd'
instance_eval &Application.config.authenticate_proc
run TDiary::Dispatcher.update
end

Expand All @@ -62,6 +62,8 @@ def call( env )
run environment
end
end

config.authenticate TDiary::Rack::Auth::Basic, '.htpasswd'
end
end

Expand Down
7 changes: 6 additions & 1 deletion tdiary/application/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module TDiary
class Application
class Configuration
attr_accessor :assets_paths, :assets_precompile, :plugin_paths, :path, :builder_procs
attr_accessor :assets_paths, :assets_precompile, :plugin_paths, :path, :builder_procs, :authenticate_proc

def initialize
@assets_paths = []
Expand All @@ -14,11 +14,16 @@ def initialize
assets: '/assets'
}
@builder_procs = []
@authenticate_proc = proc { }
end

def builder(&block)
@builder_procs << block
end

def authenticate(middleware, *params, &block)
@authenticate_proc = proc { use middleware, *params, &block }
end
end
end
end
Expand Down
6 changes: 5 additions & 1 deletion tdiary/application/extensions/omniauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

TDiary::Application.configure do
config.builder do
# TODO: use autoload
use ::Rack::Session::Pool, :expire_after => 2592000
use OmniAuth::Builder do
configure {|conf| conf.path_prefix = "/auth" }
Expand All @@ -16,4 +15,9 @@
run TDiary::Rack::Auth::OmniAuth::CallbackHandler.new
end
end

config.authenticate TDiary::Rack::Auth::OmniAuth, :twitter do |auth|
# TODO: an user can setting
auth.info.nickname == 'your_twitter_screen_name'
end
end

0 comments on commit 88c63b9

Please sign in to comment.