Class: RubynCode::Auth::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyn_code/auth/server.rb

Defined Under Namespace

Classes: CallbackTimeout

Constant Summary collapse

LISTEN_HOST =
'127.0.0.1'
LISTEN_PORT =
19_275

Instance Method Summary collapse

Constructor Details

#initializeServer

Returns a new instance of Server.



15
16
17
18
19
# File 'lib/rubyn_code/auth/server.rb', line 15

def initialize
  @result = nil
  @mutex = Mutex.new
  @condvar = ConditionVariable.new
end

Instance Method Details

#wait_for_callback(timeout: 120) ⇒ Object

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rubyn_code/auth/server.rb', line 21

def wait_for_callback(timeout: 120)
  server = build_server
  thread = Thread.new { server.start }

  @mutex.synchronize do
    @condvar.wait(@mutex, timeout) until @result || timed_out?(timeout)
  end

  server.shutdown
  thread.join(5)

  raise CallbackTimeout, "OAuth callback was not received within #{timeout} seconds" unless @result

  @result
end