Class: JunglePath::Rack::BasicCredentials::Basic
- Inherits:
-
Rack::Auth::AbstractHandler
- Object
- Rack::Auth::AbstractHandler
- JunglePath::Rack::BasicCredentials::Basic
- Defined in:
- lib/jungle_path/rack/basic_credentials.rb
Overview
Rack::Auth::Basic implements HTTP Basic Authentication, as per RFC 2617.
Initialize with the Rack application that you want protecting, and a block that checks if a username and password pair are valid.
See also: example/protectedlobster.rb
Defined Under Namespace
Classes: Request
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, realm = nil, issue_challenge = true, &authenticator) ⇒ Basic
constructor
A new instance of Basic.
Constructor Details
#initialize(app, realm = nil, issue_challenge = true, &authenticator) ⇒ Basic
Returns a new instance of Basic.
18 19 20 21 |
# File 'lib/jungle_path/rack/basic_credentials.rb', line 18 def initialize(app, realm=nil, issue_challenge=true, &authenticator) @issue_challenge = issue_challenge super(app, realm, &authenticator) end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/jungle_path/rack/basic_credentials.rb', line 23 def call(env) #puts "realm: #{realm}." auth = Basic::Request.new(env) if @issue_challenge return unless auth.provided? return bad_request unless auth.basic? end if auth.provided? and auth.basic? env['REMOTE_USER'] = auth.username env['REMOTE_PASSWORD'] = auth.password else env['REMOTE_USER'] = nil env['REMOTE_PASSWORD'] = nil end @app.call(env) end |