-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for the AzureSDK #542
Conversation
See https://github.com/tamram/storage-dotnet-azure-ad-msal/tree/tamram-0818 ``` [AuthorizeForScopes(Scopes = new string[] { "https://storage.azure.com/user_impersonation" })] public async Task<IActionResult> Blob() { var scopes = new string[] { "https://storage.azure.com/user_impersonation" }; // I guess the Blob SDK knows already? ViewData["Message"] = await CreateBlob(new TokenAcquisitionTokenCredential(_tokenAcquisition),); return View(); } private static async Task<string> CreateBlob(TokenAcquisitionTokenCredential tokenCredential) { // Replace the URL below with the URL to your blob. Uri blobUri = new Uri("https://storagesamples.blob.core.windows.net/sample-container/blob1.txt"); BlobClient blobClient = new BlobClient(blobUri, tokenCredential); // Create a blob on behalf of the user. string blobContents = "Blob created by Azure AD authenticated user."; byte[] byteArray = Encoding.ASCII.GetBytes(blobContents); using (MemoryStream stream = new MemoryStream(byteArray)) { await blobClient.UploadAsync(stream); } return "Blob successfully created"; } ```
@schaabs : do you want to have a look? |
@jennyf19 cc: @henrik-me : we are going to take this PR |
AuthenticationResult result = _tokenAcquisition.GetAuthenticationResultForUserAsync(requestContext.Scopes) | ||
.GetAwaiter() | ||
.GetResult(); | ||
return new AccessToken(result.AccessToken, result.ExpiresOn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could result be null?
public override async ValueTask<AccessToken> GetTokenAsync(TokenRequestContext requestContext, CancellationToken cancellationToken) | ||
{ | ||
AuthenticationResult result = await _tokenAcquisition.GetAuthenticationResultForUserAsync(requestContext.Scopes).ConfigureAwait(false); | ||
return new AccessToken(result.AccessToken, result.ExpiresOn); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as above, and how do we test this?
Included in 1.9.0 release |
@jmprieur What would it look like when developing a multi-tenant application with requirements to authenticate as an application/service principal? Would it be best to use |
@harris-boyce please see this for authenticating using managed identity. Note that SPs currently do not work cross-tenant in the way you describe. https://docs.microsoft.com/en-us/azure/storage/blobs/authorize-managed-identity |
Microsoft.Identity.Web leverages Azure.Identity to get the client certs and decrypt certs from keyvault. |
@jmprieur My scenarios cover the need to leverage the Azure SDK management libraries to operate against Azure resources as both the app principal and on-behalf-of the signed in user. For example:
In both cases above, I have worked around this thus far by creating my own implementations of I would be willing to contribute this code to the project as it feels like this could be a valid use case beyond my scenarios. Thoughts?
@maliksahil I'm not sure why this would be the case; my understanding is that managed identities are simply special implementations of Service Principals, so why wouldn't I be able to grant RBAC Data Reader rights to a service principal and use it to perform operations against a storage account? |
@harris-boyce : sure, feel free to contribute. Would it be a change on TokenAcquisitionTokenCredential? |
See https://github.com/tamram/storage-dotnet-azure-ad-msal/tree/tamram-0818