Class: RubstApi::Security::HTTPBasic

Inherits:
Base
  • Object
show all
Defined in:
lib/rubst_api/security.rb

Instance Attribute Summary

Attributes inherited from Base

#auto_error, #description, #scheme_name

Instance Method Summary collapse

Methods inherited from Base

#fail_auth, #initialize

Constructor Details

This class inherits a constructor from RubstApi::Security::Base

Instance Method Details

#call(request:) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/rubst_api/security.rb', line 37

def call(request:)
  scheme, credentials = request.headers["authorization"]&.split(" ", 2)
  return fail_auth unless scheme&.casecmp?("Basic") && credentials
  username, password = Base64.strict_decode64(credentials).split(":", 2)
  HTTPBasicCredentials.new(username, password)
rescue StandardError
  raise if auto_error
  nil
end

#openapi_schemeObject



46
# File 'lib/rubst_api/security.rb', line 46

def openapi_scheme = { type: "http", scheme: "basic", description: description }.compact