Interface ICredentialsProvider
- Namespace
- DynaSharp.Credentials
- Assembly
- DynaSharp.dll
Supplies the credentials used to sign each request.
public interface ICredentialsProvider
Remarks
Called for every attempt of every request, so implementations must be cheap when credentials are cached and must be thread-safe. Return the same AwsCredentials instance for as long as the credentials are unchanged: the signer caches its derived signing key per instance. A provider whose credentials can be replaced before they run out also implements IRefreshableCredentialsProvider, so that the client can recover from credentials that DynamoDB rejects as expired.
An adapter over another SDK, whose credentials come as a new object per call, keeps the instance it made until they change:
public sealed class OtherSdkCredentialsProvider(OtherSdkCredentials source) : ICredentialsProvider
{
private volatile AwsCredentials? _current;
public async ValueTask<AwsCredentials> GetCredentialsAsync(CancellationToken cancellationToken)
{
var latest = await source.GetAsync(cancellationToken);
var current = _current;
if (current is null || current.AccessKeyId != latest.AccessKey || current.SecretAccessKey != latest.SecretKey || current.SessionToken != latest.Token)
{
current = new AwsCredentials(latest.AccessKey, latest.SecretKey, latest.Token);
_current = current;
}
return current;
}
}
Methods
GetCredentialsAsync(CancellationToken)
Gets the current credentials.
ValueTask<AwsCredentials> GetCredentialsAsync(CancellationToken cancellationToken)
Parameters
cancellationTokenCancellationTokenCancels a pending credential lookup.
Returns
- ValueTask<AwsCredentials>
The credentials.
Exceptions
- CredentialsUnavailableException
No credentials can be found.