Class: RubyCoded::Auth::OAuthCallbackServer

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_coded/auth/oauth_callback_server.rb

Overview

This class is used to start a local webrick server for the OAuth authentication callback

Constant Summary collapse

PORT =
1_455
TIMEOUT =
120

Instance Method Summary collapse

Constructor Details

#initializeOAuthCallbackServer

Returns a new instance of OAuthCallbackServer.



16
17
18
19
20
# File 'lib/ruby_coded/auth/oauth_callback_server.rb', line 16

def initialize
  @result_queue = Queue.new
  @server = WEBrick::HTTPServer.new(Port: PORT, Logger: WEBrick::Log.new(File::NULL), AccessLog: [])
  @server.mount "/auth/callback", CallbackServlet, @result_queue
end

Instance Method Details

#shutdownObject



32
33
34
35
# File 'lib/ruby_coded/auth/oauth_callback_server.rb', line 32

def shutdown
  @server.shutdown
  @thread&.join(5)
end

#startObject



22
23
24
# File 'lib/ruby_coded/auth/oauth_callback_server.rb', line 22

def start
  @thread = Thread.new { @server.start }
end

#wait_for_callbackObject



26
27
28
29
30
# File 'lib/ruby_coded/auth/oauth_callback_server.rb', line 26

def wait_for_callback
  Timeout.timeout(TIMEOUT) { @result_queue.pop }
ensure
  shutdown
end