Module: Roy::BasicAuth::InstanceMethods
- Defined in:
- lib/roy/basic_auth.rb
Instance Method Summary collapse
-
#authorized?(data = nil) ⇒ Boolean
Runs the authentication logic against the user and passord given in the request, using custom additional data.
-
#protected!(data = nil) ⇒ Object
Protect all subsequent code using HTTP Basic Authentication.
Instance Method Details
#authorized?(data = nil) ⇒ Boolean
Runs the authentication logic against the user and passord given in the request, using custom additional data.
66 67 68 69 70 71 72 73 |
# File 'lib/roy/basic_auth.rb', line 66 def (data=nil) auth = Rack::Auth::Basic::Request.new(request.env) auth.provided? && auth.basic? && auth.credentials && (conf.auth[:logic] || ->(data, u, p) { %w(admin password) == [u, p] }).(data, *auth.credentials) end |
#protected!(data = nil) ⇒ Object
Protect all subsequent code using HTTP Basic Authentication.
54 55 56 57 58 59 60 |
# File 'lib/roy/basic_auth.rb', line 54 def protected!(data=nil) unless (data) realm = conf.auth && conf.auth[:realm] || 'Realm' response['WWW-Authenticate'] = %(Basic realm="#{realm}") halt 401 end end |