Module: Aspera::WebAuth::Relay
- Defined in:
- lib/aspera/web_auth/relay.rb
Overview
Login on the workstation that has the browser, for ascli that runs on another host (option ui.web_auth=paste).
The remote ascli gives a code (SealedHash) with the URL of the login page, the loopback URL to which the browser is redirected,
and the keys of the reply. Here, a local server receives the redirection, and the page shown in the browser gives a code (type reply)
to paste in the terminal of the remote ascli.
Defined Under Namespace
Classes: Login
Class Method Summary collapse
-
.parse(data) ⇒ Login
The code comes from another host, or from a message: its content is checked.
-
.run(login) ⇒ nil
Open the login page, receive the redirection, and show the code to the user in the browser.
Class Method Details
.parse(data) ⇒ Login
The code comes from another host, or from a message: its content is checked.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/aspera/web_auth/relay.rb', line 38 def parse(data) Aspera.assert_type(data, Hash, type: ParameterError) { 'login code' } login_url = parse_uri(data['login_url'], 'login_url') raise ParameterError, "URL of the login page shall be https: #{login_url.scheme}://#{login_url.host}" unless login_url.scheme.eql?('https') raise ParameterError, 'URL of the login page has no host' if login_url.host.to_s.empty? redirect = parse_uri(data['redirect_uri'], 'redirect_uri') raise ParameterError, "redirect_uri shall be http or https, with a port: #{redirect}" unless %w[http https].include?(redirect.scheme) && redirect.port raise ParameterError, "redirect_uri host shall be loopback (localhost, 127.0.0.0/8, ::1): #{redirect.host}" unless WebServerSimple.loopback?(redirect.hostname.to_s) keys = data['reply_keys'] valid_keys = keys.is_a?(Array) && !keys.empty? && keys.length <= MAX_REPLY_KEYS && keys.all? { |key| key.is_a?(String) && key.match?(REPLY_KEY_REGEX) } raise ParameterError, 'reply_keys shall be a list of parameter names' unless valid_keys Login.new(login_url: login_url, redirect_uri: redirect.to_s, reply_keys: keys, host: login_url.host.downcase) end |
.run(login) ⇒ nil
Open the login page, receive the redirection, and show the code to the user in the browser.
55 56 57 58 59 60 61 62 |
# File 'lib/aspera/web_auth/relay.rb', line 55 def run(login) server = Server.new(login.redirect_uri, "#{login.host} - login for ascli on another host", reply_keys: login.reply_keys) Environment.instance.open_uri(login.login_url) server.received_request # the page that gives the code is sent after the request is received: wait for it before ending server.wait_stopped nil end |