Class: RubyLLM::MCP::Auth::Flows::ClientCredentialsFlow
- Inherits:
-
Object
- Object
- RubyLLM::MCP::Auth::Flows::ClientCredentialsFlow
- Defined in:
- lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb
Overview
Orchestrates OAuth 2.1 Client Credentials flow Used for application authentication without user interaction
Instance Attribute Summary collapse
-
#client_registrar ⇒ Object
readonly
Returns the value of attribute client_registrar.
-
#discoverer ⇒ Object
readonly
Returns the value of attribute discoverer.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#token_manager ⇒ Object
readonly
Returns the value of attribute token_manager.
Instance Method Summary collapse
-
#execute(server_url, redirect_uri, scope, resource_metadata: nil) ⇒ Token
Perform client credentials flow.
-
#initialize(discoverer:, client_registrar:, token_manager:, storage:, logger:) ⇒ ClientCredentialsFlow
constructor
A new instance of ClientCredentialsFlow.
Constructor Details
#initialize(discoverer:, client_registrar:, token_manager:, storage:, logger:) ⇒ ClientCredentialsFlow
Returns a new instance of ClientCredentialsFlow.
12 13 14 15 16 17 18 |
# File 'lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb', line 12 def initialize(discoverer:, client_registrar:, token_manager:, storage:, logger:) @discoverer = discoverer @client_registrar = client_registrar @token_manager = token_manager @storage = storage @logger = logger end |
Instance Attribute Details
#client_registrar ⇒ Object (readonly)
Returns the value of attribute client_registrar.
10 11 12 |
# File 'lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb', line 10 def client_registrar @client_registrar end |
#discoverer ⇒ Object (readonly)
Returns the value of attribute discoverer.
10 11 12 |
# File 'lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb', line 10 def discoverer @discoverer end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb', line 10 def logger @logger end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
10 11 12 |
# File 'lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb', line 10 def storage @storage end |
#token_manager ⇒ Object (readonly)
Returns the value of attribute token_manager.
10 11 12 |
# File 'lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb', line 10 def token_manager @token_manager end |
Instance Method Details
#execute(server_url, redirect_uri, scope, resource_metadata: nil) ⇒ Token
Perform client credentials flow
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ruby_llm/mcp/auth/flows/client_credentials_flow.rb', line 26 def execute(server_url, redirect_uri, scope, resource_metadata: nil) logger.debug("Starting OAuth client credentials flow") # 1. Discover authorization server = discoverer.discover(server_url, resource_metadata_url: ) raise Errors::TransportError.new(message: "OAuth server discovery failed") unless # 2. Register client (or get cached client) with client credentials grant client_info = client_registrar.get_or_register( server_url, , :client_credentials, redirect_uri, scope ) # 3. Validate that we have a client secret unless client_info.client_secret raise Errors::TransportError.new( message: "Client credentials flow requires client_secret" ) end # 4. Exchange client credentials for token token = token_manager.exchange_client_credentials( , client_info, scope, server_url ) # 5. Store token storage.set_token(server_url, token) logger.info("Client credentials authentication completed successfully") token end |