You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
The Azure SDK has the notion of TokenCredential which is used by various SDKs. It's possible to derive from TokenCredential to provide credentials coming from Microsoft.Identity.Web, however this requires both the token and the expiry. ITokenAcquisition covers the simple scenario where the token is returned, but not the expiry.
In a controller accessing a blob storage customers could write:
[AuthorizeForScopes(Scopes =newstring[]{"https://storage.azure.com/user_impersonation"})]publicasyncTask<IActionResult>Blob(){varscopes=newstring[]{"https://storage.azure.com/user_impersonation"};// I guess the Blob SDK knows already?
ViewData["Message"]=await CreateBlob(new TokenAcquisitionTokenCredential(_tokenAcquisition),);return View();}privatestaticasyncTask<string>CreateBlob(TokenAcquisitionTokenCredentialtokenCredential){// Replace the URL below with the URL to your blob.UriblobUri=new Uri("https://storagesamples.blob.core.windows.net/sample-container/blob1.txt");BlobClientblobClient=new BlobClient(blobUri, tokenCredential);// Create a blob on behalf of the user.stringblobContents="Blob created by Azure AD authenticated user.";byte[]byteArray= Encoding.ASCII.GetBytes(blobContents);using(MemoryStreamstream=new MemoryStream(byteArray)){await blobClient.UploadAsync(stream);}return"Blob successfully created";}
with
/// <summary>/// Azure SDK token credential based on the ITokenAcquisition service./// </summary>publicclassTokenAcquisitionTokenCredential:TokenCredential{privateITokenAcquisition_tokenAcquisition;/// <summary>/// Constructor from an ITokenAcquisition service./// </summary>/// <param name="tokenAcquisition">Token acquisition.</param>publicTokenAcquisitionTokenCredential(ITokenAcquisitiontokenAcquisition){_tokenAcquisition=tokenAcquisition;}/// <inheritdoc/>publicoverride AccessToken GetToken(TokenRequestContextrequestContext,CancellationTokencancellationToken){AuthenticationResultresult= _tokenAcquisition.GetAuthenticationResultForUserAsync(requestContext.Scopes).GetAwaiter().GetResult();returnnew AccessToken(result.AccessToken, result.ExpiresOn);}/// <inheritdoc/>publicoverrideasyncValueTask<AccessToken>GetTokenAsync(TokenRequestContextrequestContext,CancellationTokencancellationToken){AuthenticationResultresult=await _tokenAcquisition.GetAuthenticationResultForUserAsync(requestContext.Scopes).ConfigureAwait(false);returnnew AccessToken(result.AccessToken, result.ExpiresOn);}}
Describe the solution you'd like
GetAuthenticationResultForUserAsync
Expose TokenAcquisitionTokenCredential (given we already leverage the Azure.Identity NuGet package)
Describe alternatives you've considered
expose the expiry as an optional ref parameter?
Expose TokenAcquisitionTokenCredential but not GetAuthenticationResultForUserAsync?
Additional context
This is mainly a refactoring of GetTokenForUserAsync by exposing an intermediate product (the AuthenticationResult)
@jennyf19@henrik-me@pmaytak
I wonder if we should not just take (for 0-4-0) the GetAuthenticationResultForUserAsync addition (as this is a small refactoring and does not even need more tests). This would unblock this scenario
But I'm not suggesting we take the TokenAcquisitionTokenCredential which requires more specs.
Is your feature request related to a problem? Please describe.
The Azure SDK has the notion of TokenCredential which is used by various SDKs. It's possible to derive from TokenCredential to provide credentials coming from Microsoft.Identity.Web, however this requires both the token and the expiry. ITokenAcquisition covers the simple scenario where the token is returned, but not the expiry.
In a controller accessing a blob storage customers could write:
with
Describe the solution you'd like
Describe alternatives you've considered
expose the expiry as an optional ref parameter?
Additional context
The text was updated successfully, but these errors were encountered: