Module: MCP::Client::OAuth::StorageBackedProvider

Included in:
ClientCredentialsProvider, Provider
Defined in:
lib/mcp/client/oauth/storage_backed_provider.rb

Overview

Shared token/credential persistence for the OAuth provider classes (‘Provider` for the authorization-code flow and `ClientCredentialsProvider` for the client_credentials flow). The two grants differ in how they authenticate, but both read and write the same two pieces of state through a `storage` object: the token response and the client information. This module supplies that delegation so the `Flow` orchestrator can treat any provider uniformly.

Including classes must set ‘@storage` to an object responding to `tokens`, `save_tokens(tokens)`, `client_information`, and `save_client_information(info)` (see `InMemoryStorage`).

Instance Method Summary collapse

Instance Method Details

#access_tokenObject



17
18
19
# File 'lib/mcp/client/oauth/storage_backed_provider.rb', line 17

def access_token
  tokens&.dig("access_token") || tokens&.dig(:access_token)
end

#clear_tokens!Object



37
38
39
# File 'lib/mcp/client/oauth/storage_backed_provider.rb', line 37

def clear_tokens!
  @storage.save_tokens(nil)
end

#client_informationObject



29
30
31
# File 'lib/mcp/client/oauth/storage_backed_provider.rb', line 29

def client_information
  @storage.client_information
end

#save_client_information(info) ⇒ Object



33
34
35
# File 'lib/mcp/client/oauth/storage_backed_provider.rb', line 33

def save_client_information(info)
  @storage.save_client_information(info)
end

#save_tokens(tokens) ⇒ Object



25
26
27
# File 'lib/mcp/client/oauth/storage_backed_provider.rb', line 25

def save_tokens(tokens)
  @storage.save_tokens(tokens)
end

#tokensObject



21
22
23
# File 'lib/mcp/client/oauth/storage_backed_provider.rb', line 21

def tokens
  @storage.tokens
end