Class: Hadley::Authz::Basic::Strategy

Inherits:
Strategy
  • Object
show all
Defined in:
lib/hadley/authz/basic.rb

Instance Method Summary collapse

Methods inherited from Strategy

#config

Methods included from StrategyBuilder

#build

Instance Method Details

#authObject



9
10
11
# File 'lib/hadley/authz/basic.rb', line 9

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

#authenticate!Object



17
18
19
20
21
22
23
24
# File 'lib/hadley/authz/basic.rb', line 17

def authenticate!
  return unauthorized unless auth.provided? and auth.basic? and auth.credentials
  credentials = auth.credentials.map do |credential|
    config.hash_credentials ? Digest::SHA2.new(256).update(credential).to_s : credential
  end
  user = config.lookup.call(credentials.first, credentials.last)
  return user ? success!(auth.credentials.first) : unauthorized
end

#store?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/hadley/authz/basic.rb', line 13

def store?
  false
end

#unauthorizedObject



26
27
28
# File 'lib/hadley/authz/basic.rb', line 26

def unauthorized
  custom!(Rack::Response.new([config.fail_message], 401, { 'WWW-Authenticate' => %Q{Basic realm="#{config.realm}"} }))
end