Module: Keycardai::OAuth::Loopback

Defined in:
lib/keycardai/oauth/authenticate.rb

Overview

Internals of the loopback flow. Not public API.

Defined Under Namespace

Classes: CallbackServer

Constant Summary collapse

SUCCESS_PAGE =
"<html><body><p>Authentication complete. You can close this window.</p></body></html>"

Class Method Summary collapse

Class Method Details

.fetch_resource_metadata(url, http_client, timeout) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
# File 'lib/keycardai/oauth/authenticate.rb', line 114

def (url, http_client, timeout)
  response = http_client.get(url, headers: { "Accept" => "application/json" }, timeout: timeout)
  unless response.success?
    raise HTTPError.new("resource metadata fetch returned HTTP #{response.status}",
                        status: response.status, body: response.body)
  end

  JSON.parse(response.body)
rescue JSON::ParserError
  raise ProtocolError.new("resource metadata is not valid JSON", code: "invalid_metadata")
end

.open_browser(url) ⇒ Object

Open the system browser without a shell.



127
128
129
130
131
132
133
134
# File 'lib/keycardai/oauth/authenticate.rb', line 127

def open_browser(url)
  command = case RUBY_PLATFORM
            when /darwin/ then ["open", url]
            when /mswin|mingw/ then ["cmd", "/c", "start", "", url]
            else ["xdg-open", url]
            end
  Process.spawn(*command, %i[out err] => File::NULL)
end