Class: Aspera::WebAuth

Inherits:
WebServerSimple show all
Defined in:
lib/aspera/web_auth.rb

Overview

start a local web server then start a browser that will callback the local server upon authentication store the final query

Instance Method Summary collapse

Methods inherited from WebServerSimple

#<<, fill_self_signed_cert, #start

Constructor Details

#initialize(endpoint_url, additionnal_info = nil) ⇒ WebAuth

Returns a new instance of WebAuth.

Parameters:



174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/aspera/web_auth.rb', line 174

def initialize(endpoint_url, additionnal_info = nil)
  uri = URI.parse(endpoint_url)
  super(uri)
  @mutex = Mutex.new
  @cond = ConditionVariable.new
  @expected_path = uri.path.empty? ? '/' : uri.path
  @query = nil
  @additionnal_info = additionnal_info
  # last argument (self) is provided to constructor of servlet
  mount(@expected_path, WebAuthServlet, self)
  # server runs in thread
  Thread.new { start }
end

Instance Method Details

#received_requestHash

wait for request on web server (main thread)

Returns:

  • (Hash)

    the query



202
203
204
205
206
207
208
# File 'lib/aspera/web_auth.rb', line 202

def received_request
  # wait for signal from thread
  @mutex.synchronize{@cond.wait(@mutex)}
  # tell server thread to stop
  shutdown
  return @query
end

#signal_request(request) ⇒ String

Called by web server thread on received request

Returns:

  • (String)

    additional information for web page

Raises:

  • (WEBrick::HTTPStatus::NotFound)


190
191
192
193
194
195
196
197
198
# File 'lib/aspera/web_auth.rb', line 190

def signal_request(request)
  raise WEBrick::HTTPStatus::NotFound, "unexpected path: #{request.path}" unless request.path.eql?(@expected_path)
  # acquire lock and signal change
  @mutex.synchronize do
    @query = request.query
    @cond.signal
  end
  return @additionnal_info
end