Class: Sinatra::Helpers::Authentication

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/basic_auth.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Authentication) initialize(app, request)

Returns a new instance of Authentication



25
26
27
28
# File 'lib/sinatra/basic_auth.rb', line 25

def initialize( app, request )
  self.app = app
  self.request = request
end

Instance Attribute Details

- (Object) app

Returns the value of attribute app



24
25
26
# File 'lib/sinatra/basic_auth.rb', line 24

def app
  @app
end

- (Object) request

Returns the value of attribute request



24
25
26
# File 'lib/sinatra/basic_auth.rb', line 24

def request
  @request
end

Instance Method Details

- (Object) auth



30
31
32
# File 'lib/sinatra/basic_auth.rb', line 30

def auth
  @basic_auth ||= Rack::Auth::Basic::Request.new( request.env )
end

- (Object) authorize(username, password)



47
48
49
50
# File 'lib/sinatra/basic_auth.rb', line 47

def authorize( username, password )
  settings.basic_auth_username == username &&
  settings.basic_auth_password == password
end

- (Boolean) authorized?

Returns:

  • (Boolean)


43
44
45
# File 'lib/sinatra/basic_auth.rb', line 43

def authorized?
  request.env['REMOTE_USER']
end

- (Object) bad_request!



39
40
41
# File 'lib/sinatra/basic_auth.rb', line 39

def bad_request!
  throw :halt, [ 400, 'Bad Request' ]
end

- (Object) unauthorized!



34
35
36
37
# File 'lib/sinatra/basic_auth.rb', line 34

def unauthorized!
  app.headers 'WWW-Authenticate' => %(Basic realm="#{settings.basic_auth_realm}")
  throw :halt, [ 401, 'Authorization Required' ]
end