-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Labels
Description
Details: #181 (comment)
How to construct StorageCredentials for Managed Identity in the code below:
var azureServiceTokenProvider = new AzureServiceTokenProvider();
var state = (azureServiceTokenProvider, settings);
var tokenAndFrequency = await TokenRenewerAsync(state, CancellationToken.None).ConfigureAwait(false);
var tokenCredential = new TokenCredential(tokenAndFrequency.Token,
TokenRenewerAsync,
state,
tokenAndFrequency.Frequency.Value);
var storageCredentials = new StorageCredentials(tokenCredential);And the method for token renewer:
static async Task<NewTokenAndFrequency> TokenRenewerAsync(object state, CancellationToken token = default)
{
var (azureServiceTokenProvider, settings) = (ValueTuple<AzureServiceTokenProvider, Settings>)state;
// Use the same token provider to request a new token.
var resourceUri = settings.BlobEndpoint;
var result = await azureServiceTokenProvider.GetAuthenticationResultAsync(resourceUri, cancellationToken: token).ConfigureAwait(false);
// Renew the token before it expires.
var next = (result.ExpiresOn - DateTimeOffset.UtcNow) - settings.RenewalTimeBeforeTokenExpires;
if (next.Ticks < 0)
{
next = default;
}
return new NewTokenAndFrequency(result.AccessToken, next);
}This could be all simplified and embedded into the plugin, but still, there'd be a need in a new configuration overload that takes in RenewalTimeBeforeTokenExpires to override the default the plugin would set. Initially, this could be just captured in the documentation, similar to how service and container SAS authentication is documented.
Reactions are currently unavailable