Tokens can be cached beyond the lifetime of the (http) transport. (#834)

This commit is contained in:
Manuel Naujoks 2025-11-25 02:56:56 +01:00 • committed by GitHub
commit 820821fa0c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -0,0 +1,27 @@
namespace ModelContextProtocol.Authentication;
/// <summary>
/// Caches the token in-memory within this instance.
/// </summary>
internal class InMemoryTokenCache : ITokenCache
{
private TokenContainer? _tokens;
/// <summary>
/// Cache the token.
/// </summary>
public ValueTask StoreTokensAsync(TokenContainer tokens, CancellationToken cancellationToken)
{
_tokens = tokens;
return default;
}
/// <summary>
/// Get the cached token.
/// </summary>
public ValueTask<TokenContainer?> GetTokensAsync(CancellationToken cancellationToken)
{
return new ValueTask<TokenContainer?>(_tokens);
}
}