Class: Clacky::Mcp::OAuth::AuthorizationManager::CallbackReceiver
- Inherits:
-
Object
- Object
- Clacky::Mcp::OAuth::AuthorizationManager::CallbackReceiver
- Defined in:
- lib/clacky/mcp/oauth/authorization_manager.rb
Instance Attribute Summary collapse
-
#redirect_uri ⇒ Object
readonly
Returns the value of attribute redirect_uri.
Instance Method Summary collapse
- #call(authorization_url, _expected_state) ⇒ Object
- #close ⇒ Object
-
#initialize(timeout: 300) ⇒ CallbackReceiver
constructor
A new instance of CallbackReceiver.
Constructor Details
#initialize(timeout: 300) ⇒ CallbackReceiver
Returns a new instance of CallbackReceiver.
218 219 220 221 222 |
# File 'lib/clacky/mcp/oauth/authorization_manager.rb', line 218 def initialize(timeout: 300) @server = TCPServer.new("127.0.0.1", 0) @timeout = timeout @redirect_uri = "http://127.0.0.1:#{@server.addr[1]}/callback" end |
Instance Attribute Details
#redirect_uri ⇒ Object (readonly)
Returns the value of attribute redirect_uri.
216 217 218 |
# File 'lib/clacky/mcp/oauth/authorization_manager.rb', line 216 def redirect_uri @redirect_uri end |
Instance Method Details
#call(authorization_url, _expected_state) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/clacky/mcp/oauth/authorization_manager.rb', line 224 def call(, _expected_state) open_browser() socket = Timeout.timeout(@timeout) { @server.accept } request_line = socket.gets.to_s path = request_line.split(" ")[1].to_s query = URI.decode_www_form(URI.parse(path).query.to_s).to_h socket.write("HTTP/1.1 200 OK\r\nContent-Type: text/plain\r\nConnection: close\r\n\r\nOpenClacky authorization complete. You may close this tab.\n") query rescue Timeout::Error raise Error, "OAuth authorization timed out" ensure socket.close if defined?(socket) && socket end |
#close ⇒ Object
238 239 240 |
# File 'lib/clacky/mcp/oauth/authorization_manager.rb', line 238 def close @server.close unless @server.closed? end |