Module: LcpRuby::Authentication::HttpFetcher
- Defined in:
- lib/lcp_ruby/authentication/http_fetcher.rb
Overview
Tiny shared HTTP-GET-JSON helper used by ProviderRegistry (discovery docs) and JwksCache (JWKS docs). Both have identical timeout/SSL needs and convert non-2xx into ConfigurationError.
Constant Summary collapse
- DEFAULT_TIMEOUT =
seconds; both open + read
5
Class Method Summary collapse
-
.get_json(url, timeout: DEFAULT_TIMEOUT) ⇒ Hash
Parsed JSON body.
Class Method Details
.get_json(url, timeout: DEFAULT_TIMEOUT) ⇒ Hash
Returns parsed JSON body.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/lcp_ruby/authentication/http_fetcher.rb', line 18 def get_json(url, timeout: DEFAULT_TIMEOUT) uri = URI.parse(url) response = Net::HTTP.start( uri.host, uri.port, use_ssl: uri.scheme == "https", open_timeout: timeout, read_timeout: timeout ) do |http| http.request(Net::HTTP::Get.new(uri.request_uri)) end unless response.is_a?(Net::HTTPSuccess) raise ConfigurationError, "GET #{url} failed: HTTP #{response.code}" end JSON.parse(response.body) end |