Module: Rapid::Server::Helpers::Auth

Defined in:
lib/ury_rapid/server/helpers/auth.rb

Overview

Sinatra helpers for using Rapid's auth system in the HTTP server

This depends on methods available in Rapid::Server::Helpers::Error.

Instance Method Summary collapse

Instance Method Details

#not_authorisedvoid

This method returns an undefined value.

Fails with a HTTP 401 Not Authorised status.


27
28
29
30
# File 'lib/ury_rapid/server/helpers/auth.rb', line 27

def not_authorised
  headers['WWW-Authenticate'] = 'Basic realm="Restricted Area"'
  error(401, 'Not authorised.')
end

#privilege_set(suppress_error = false) ⇒ Array

Gets the set of privileges the user has

This fails with HTTP 401 if the user does not exist.


17
18
19
20
21
22
# File 'lib/ury_rapid/server/helpers/auth.rb', line 17

def privilege_set(suppress_error = false)
  rack_auth = Rack::Auth::Basic::Request.new(request.env)
  AuthRequest.request(environment, rack_auth)
rescue Kankri::AuthenticationFailure
  not_authorised unless suppress_error
end