|
10 | 10 | using System.Threading.Tasks; |
11 | 11 | using Autofac; |
12 | 12 | using Autofac.Core; |
13 | | -using Azure.Core; |
14 | 13 | using Azure.Identity; |
15 | 14 | using Azure.Storage.Blobs; |
16 | 15 | using Microsoft.ApplicationInsights; |
@@ -621,27 +620,29 @@ private static BlobServiceClient CreateBlobServiceClient( |
621 | 620 | { |
622 | 621 | if (string.IsNullOrWhiteSpace(msiConfiguration.ManagedIdentityClientId)) |
623 | 622 | { |
624 | | - // Using MSI with DefaultAzureCredential (local debugging) |
| 623 | + // 1. Using MSI with DefaultAzureCredential (local debugging) |
625 | 624 | var defaultAzureCredentialOptions = new DefaultAzureCredentialOptions |
626 | 625 | { |
627 | | - ManagedIdentityClientId = msiConfiguration.ManagedIdentityClientId, |
| 626 | + ManagedIdentityClientId = null, |
628 | 627 | }; |
629 | | - var tokenCredential = new DefaultAzureCredential(defaultAzureCredentialOptions); |
630 | 628 |
|
631 | | - return new BlobServiceClient(new Uri(storageConnectionString), tokenCredential, blobClientOptions); |
| 629 | + return new BlobServiceClient( |
| 630 | + ConnectionStringExtensions.GetBlobEndpointFromConnectionString(storageConnectionString), |
| 631 | + new DefaultAzureCredential(defaultAzureCredentialOptions), |
| 632 | + blobClientOptions); |
632 | 633 | } |
633 | 634 | else |
634 | 635 | { |
635 | | - // Using MSI with ClientId |
636 | | - var tokenCredential = new ManagedIdentityCredential(msiConfiguration.ManagedIdentityClientId); |
637 | | - |
638 | | - return new BlobServiceClient(new Uri(storageConnectionString), tokenCredential, blobClientOptions); |
| 636 | + // 2. Using MSI with ClientId |
| 637 | + return new BlobServiceClient( |
| 638 | + ConnectionStringExtensions.GetBlobEndpointFromConnectionString(storageConnectionString), |
| 639 | + new ManagedIdentityCredential(msiConfiguration.ManagedIdentityClientId), |
| 640 | + blobClientOptions); |
639 | 641 | } |
640 | 642 | } |
641 | 643 | else |
642 | 644 | { |
643 | | - // Using SAS token |
644 | | - |
| 645 | + // 3. Using SAS token |
645 | 646 | // workaround for https://github.com/Azure/azure-sdk-for-net/issues/44373 |
646 | 647 | var connectionString = storageConnectionString.Replace("SharedAccessSignature=?", "SharedAccessSignature="); |
647 | 648 |
|
|
0 commit comments