Tokens can be cached beyond the lifetime of the (http) transport. (#834)
This commit is contained in:
parent
e6db415940
commit
820821fa0c
1 changed files with 538 additions and 373 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue