Class: Kreator::Providers::OpenAIAuth::OAuthCallbackServer
- Inherits:
-
Object
- Object
- Kreator::Providers::OpenAIAuth::OAuthCallbackServer
- Defined in:
- lib/kreator/providers/openai_auth.rb
Constant Summary collapse
- CALLBACK_PATH =
"/auth/callback"
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(state:, host:, port:) ⇒ OAuthCallbackServer
constructor
A new instance of OAuthCallbackServer.
- #start ⇒ Object
- #wait(timeout) ⇒ Object
Constructor Details
#initialize(state:, host:, port:) ⇒ OAuthCallbackServer
Returns a new instance of OAuthCallbackServer.
429 430 431 432 433 434 |
# File 'lib/kreator/providers/openai_auth.rb', line 429 def initialize(state:, host:, port:) @state = state @host = host @port = port @queue = Queue.new end |
Class Method Details
.start(state:, redirect_uri:) ⇒ Object
424 425 426 427 |
# File 'lib/kreator/providers/openai_auth.rb', line 424 def self.start(state:, redirect_uri:) uri = URI(redirect_uri) new(state: state, host: ENV.fetch("PI_OAUTH_CALLBACK_HOST", "127.0.0.1"), port: uri.port || 1455).tap(&:start) end |
Instance Method Details
#close ⇒ Object
450 451 452 453 454 455 |
# File 'lib/kreator/providers/openai_auth.rb', line 450 def close @server&.close @thread&.kill rescue IOError nil end |
#start ⇒ Object
436 437 438 439 440 441 442 |
# File 'lib/kreator/providers/openai_auth.rb', line 436 def start @server = TCPServer.new(@host, @port) @thread = Thread.new { accept_callback } self rescue SystemCallError => e raise Error.new("failed to start OpenAI OAuth callback server on #{@host}:#{@port}: #{e.}", code: "oauth_callback_server_failed") end |
#wait(timeout) ⇒ Object
444 445 446 447 448 |
# File 'lib/kreator/providers/openai_auth.rb', line 444 def wait(timeout) @queue.pop(timeout: timeout) rescue ThreadError nil end |