module Shaf::Authenticator

Public Class Methods

challenges_for(realm: nil) click to toggle source
# File lib/shaf/authenticator.rb, line 16
def challenges_for(realm: nil)
  authenticators.each_with_object([]) do |authenticator, challenges|
    challenges.concat Array(authenticator.challenges_for(realm))
  end
end
register(authenticator) click to toggle source
# File lib/shaf/authenticator.rb, line 8
def register(authenticator)
  authenticators << authenticator
end
unregister(authenticator) click to toggle source
# File lib/shaf/authenticator.rb, line 12
def unregister(authenticator)
  authenticators.delete_if { |auth| auth == authenticator }
end
user(env, realm: nil) click to toggle source
# File lib/shaf/authenticator.rb, line 22
def user(env, realm: nil)
  request = Request.new(env)
  return unless request.provided?

  authenticator = authenticator_for(request)
  authenticator&.user(request, realm: realm)
end

Private Class Methods

authenticator_for(request) click to toggle source
# File lib/shaf/authenticator.rb, line 36
def authenticator_for(request)
  scheme = request.scheme
  authenticator = authenticators.find { |auth| auth.scheme? scheme }

  logger.warn(
    "Client tried to authenticate with an unsupported " \
    "authentication scheme: #{scheme}"
  ) unless authenticator

  authenticator
end
authenticators() click to toggle source
# File lib/shaf/authenticator.rb, line 32
def authenticators
  @authenticators ||= Set.new
end
logger() click to toggle source
# File lib/shaf/authenticator.rb, line 48
def logger
  Shaf.logger
end