Class: Modern::Descriptor::Security::Http

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

Constant Summary collapse

SPLITTER =

aside: some people think that the Authorization field can support multiple sets of credentials, as RFC 7230 suggests that headers can be sent “multiple” times by using a comma to split them. however, this is for headers like Accept-Encoding. We don’t need to split Authorization.

%r,([^\s]+?)\s+(.*+),

Instance Method Summary collapse

Methods inherited from Base

#validate

Methods included from Struct::Copy

#copy

Instance Method Details

#do_credential_fetch(request) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/modern/descriptor/security.rb', line 82

def do_credential_fetch(request)
  header = request.env["HTTP_AUTHORIZATION"]

  if header.nil?
    nil
  else
    match = SPLITTER.match(header)
    # yields #<MatchData "Bearer foo" 1:"Bearer" 2:"foo">

    match[2].strip if !match.nil? && match[1].casecmp(scheme).zero?
  end
end

#to_openapi3Object



95
96
97
98
99
100
# File 'lib/modern/descriptor/security.rb', line 95

def to_openapi3
  super.merge(
    type: "http",
    scheme: scheme
  )
end