Skip to content

Document how to use the plugin (v6) with Managed Identity #208

@SeanFeldman

Description

@SeanFeldman

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions