class KeycloakRack::SkipAuthentication

Check if the request should be skipped based on the request method and path.

@api private @!visibility private

Public Instance Methods

call(env) click to toggle source

@return [Dry::Monads::Success(Boolean)]

# File lib/keycloak_rack/skip_authentication.rb, line 16
def call(env)
  method = env["REQUEST_METHOD"].to_s.downcase
  path   = env["PATH_INFO"]

  return Success(true) if preflight?(method, env)
  return Success(true) if should_skip?(method, path)

  Success(false)
end

Private Instance Methods

preflight?(method, headers) click to toggle source
# File lib/keycloak_rack/skip_authentication.rb, line 40
def preflight?(method, headers)
  method == "options" && headers["HTTP_ACCESS_CONTROL_REQUEST_METHOD"].present?
end
should_skip?(method, path) click to toggle source
# File lib/keycloak_rack/skip_authentication.rb, line 28
def should_skip?(method, path)
  method_paths = skip_paths.fetch(method, [])

  method_paths.any? do |path_pattern|
    if path_pattern.kind_of?(Regexp)
      path_pattern.match? path
    else
      path_pattern == path
    end
  end
end