Module: Roy::BasicAuth

Defined in:
lib/roy/basic_auth.rb

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) authorized?(data = nil)

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
# File 'lib/roy/basic_auth.rb', line 11

def authorized?(data=nil)
  auth = Rack::Auth::Basic::Request.new(roy.request.env)

  auth.provided? && auth.basic? && auth.credentials &&
    (roy.conf.auth[:logic] || ->(data, u, p) {
      %w(admin password) == [u, p]
     }).(data, *auth.credentials)
end

- (Object) protected!(data = nil)



3
4
5
6
7
8
9
# File 'lib/roy/basic_auth.rb', line 3

def protected!(data=nil)
  unless authorized?(data)
    realm = roy.conf.auth && roy.conf.auth[:realm] || 'Realm'
    roy.response['WWW-Authenticate'] = %(Basic realm="#{realm}")
    roy.halt 401
  end
end