Class: TokenEndpoint::Discover

Inherits:
Object
  • Object
show all
Defined in:
lib/token_endpoint/discover.rb

Constant Summary collapse

REGEXP_REG_REL_TYPE_PATTERN =

Ultra-orthodox pattern matching allowed values in HTTP Link header ‘rel` parameter tools.ietf.org/html/rfc8288#section-3.3

'[a-z\d][a-z\d\-\.]*'.freeze
REGEXP_TARGET_URI_PATTERN =

Liberal pattern matching a string of text between angle brackets tools.ietf.org/html/rfc5988#section-5.1

/^<(.*)>;/
REGEXP_TOKEN_ENDPOINT_REL_PATTERN =

Ultra-orthodox pattern matching HTTP Link header ‘rel` parameter including an `token_endpoint` value www.w3.org/TR/indieauth/#x4-discovery

/(?:;|\s)rel="?(?:#{REGEXP_REG_REL_TYPE_PATTERN}+\s)?token_endpoint(?:\s#{REGEXP_REG_REL_TYPE_PATTERN})?"?/

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Discover

Returns a new instance of Discover.

Raises:



15
16
17
18
19
# File 'lib/token_endpoint/discover.rb', line 15

def initialize(response)
  raise ArgumentError, "response must be an HTTP::Response (given #{response.class.name})" unless response.is_a?(HTTP::Response)

  @response = response
end

Instance Method Details

#endpointObject



21
22
23
24
25
26
27
# File 'lib/token_endpoint/discover.rb', line 21

def endpoint
  return unless endpoint_from_http_request

  @endpoint ||= Absolutely.to_absolute_uri(base: @response.uri.to_s, relative: endpoint_from_http_request)
rescue Absolutely::InvalidURIError => error
  raise InvalidURIError, error
end