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

Included in:
ClientCredentialsProvider, CrossAppAccessProvider, 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 Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#authorization_request_validatorObject (readonly)

Optional ->(request) { true | false } hook, called with an AuthorizationRequest. An MCP server names its own authorization server and the scopes to ask for, so this is where an embedding application sees both before the request is made and can decline to proceed. nil (the default) authorizes whatever the server asked for, which is the behavior every MCP SDK has today.



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

def authorization_request_validator
  @authorization_request_validator
end

Instance Method Details

#access_tokenObject



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

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

#clear_tokens!Object



44
45
46
# File 'lib/mcp/client/oauth/storage_backed_provider.rb', line 44

def clear_tokens!
  @storage.save_tokens(nil)
end

#client_informationObject



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

def client_information
  @storage.client_information
end

#save_client_information(info) ⇒ Object



40
41
42
# File 'lib/mcp/client/oauth/storage_backed_provider.rb', line 40

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

#save_tokens(tokens) ⇒ Object



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

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

#tokensObject



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

def tokens
  @storage.tokens
end