Class: HTTP::TokenAuth::AuthorizationHeaderParser

Inherits:
Object
  • Object
show all
Defined in:
lib/http/token_auth/authorization_header_parser.rb

Instance Method Summary collapse

Constructor Details

#initializeAuthorizationHeaderParser

Returns a new instance of AuthorizationHeaderParser.



12
13
14
# File 'lib/http/token_auth/authorization_header_parser.rb', line 12

def initialize
  @scheme_parser = SchemeParser.new
end

Instance Method Details

#build_credentials(attributes) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/http/token_auth/authorization_header_parser.rb', line 20

def build_credentials(attributes)
  Credentials.new token: attributes[:token],
                  coverage: parse_coverage(attributes[:coverage]),
                  nonce: attributes[:nonce],
                  auth: attributes[:auth],
                  timestamp: parse_timestamp(attributes[:timestamp])
rescue CredentialsArgumentError => e
  raise AuthorizationHeaderParsingError, e.message
end

#parse(header) ⇒ Object



16
17
18
# File 'lib/http/token_auth/authorization_header_parser.rb', line 16

def parse(header)
  build_credentials @scheme_parser.parse(header)
end

#parse_coverage(string) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/http/token_auth/authorization_header_parser.rb', line 30

def parse_coverage(string)
  case string
  when nil
  when ''
  when 'none' then :none
  when 'base' then :base
  when 'base+body-sha-256' then :base_body_sha_256
  else raise AuthorizationHeaderParsingError, %(Unsupported coverage "#{string}")
  end
end

#parse_timestamp(string) ⇒ Object



41
42
43
# File 'lib/http/token_auth/authorization_header_parser.rb', line 41

def parse_timestamp(string)
  string.nil? ? nil : string.to_i
end