Class: RubyLLM::MCP::Auth::Browser::CallbackHandler
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Auth::Browser::CallbackHandler
- Defined in:
- lib/ruby_llm/mcp/auth/browser/callback_handler.rb
Overview
Handles OAuth callback request processing Extracts and validates OAuth parameters from callback requests
Instance Attribute Summary collapse
-
#callback_path ⇒ Object
readonly
Returns the value of attribute callback_path.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
-
#extract_oauth_params(params) ⇒ Hash
Extract OAuth parameters from parsed params.
-
#initialize(callback_path:, logger: nil) ⇒ CallbackHandler
constructor
A new instance of CallbackHandler.
-
#parse_callback_params(path, http_server) ⇒ Hash
Parse callback parameters from path.
-
#update_result_with_oauth_params(oauth_params, result, mutex, condition) ⇒ Object
Update result hash with OAuth parameters (thread-safe).
-
#valid_callback_path?(path) ⇒ Boolean
Validate that the request path matches the expected callback path.
Constructor Details
#initialize(callback_path:, logger: nil) ⇒ CallbackHandler
Returns a new instance of CallbackHandler.
12 13 14 15 |
# File 'lib/ruby_llm/mcp/auth/browser/callback_handler.rb', line 12 def initialize(callback_path:, logger: nil) @callback_path = callback_path @logger = logger || MCP.logger end |
Instance Attribute Details
#callback_path ⇒ Object (readonly)
Returns the value of attribute callback_path.
10 11 12 |
# File 'lib/ruby_llm/mcp/auth/browser/callback_handler.rb', line 10 def callback_path @callback_path end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/ruby_llm/mcp/auth/browser/callback_handler.rb', line 10 def logger @logger end |
Instance Method Details
#extract_oauth_params(params) ⇒ Hash
Extract OAuth parameters from parsed params
39 40 41 42 43 44 45 46 |
# File 'lib/ruby_llm/mcp/auth/browser/callback_handler.rb', line 39 def extract_oauth_params(params) { code: params["code"], state: params["state"], error: params["error"], error_description: params["error_description"] } end |
#parse_callback_params(path, http_server) ⇒ Hash
Parse callback parameters from path
29 30 31 32 33 34 |
# File 'lib/ruby_llm/mcp/auth/browser/callback_handler.rb', line 29 def parse_callback_params(path, http_server) _, query_string = path.split("?", 2) params = http_server.parse_query_params(query_string || "") @logger.debug("Callback params: #{params.keys.join(', ')}") params end |
#update_result_with_oauth_params(oauth_params, result, mutex, condition) ⇒ Object
Update result hash with OAuth parameters (thread-safe)
53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/ruby_llm/mcp/auth/browser/callback_handler.rb', line 53 def update_result_with_oauth_params(oauth_params, result, mutex, condition) mutex.synchronize do if oauth_params[:error] result[:error] = oauth_params[:error_description] || oauth_params[:error] elsif oauth_params[:code] && oauth_params[:state] result[:code] = oauth_params[:code] result[:state] = oauth_params[:state] else result[:error] = "Invalid callback: missing code or state parameter" end result[:completed] = true condition.signal end end |
#valid_callback_path?(path) ⇒ Boolean
Validate that the request path matches the expected callback path
20 21 22 23 |
# File 'lib/ruby_llm/mcp/auth/browser/callback_handler.rb', line 20 def valid_callback_path?(path) uri_path, = path.split("?", 2) uri_path == @callback_path end |