Skip to content

[BUG] TokenCredential of AddBlobServiceClient(...) is always DefaultAzureCredential #50084

Open
@lschoenawa

Description

@lschoenawa

Library name and version

Microsoft.Extensions.Azure 1.11.0

Describe the bug

Within the BlobClientBuilderExtensions the method

public static IAzureClientBuilder<BlobServiceClient, BlobClientOptions> AddBlobServiceClient<TBuilder>(this TBuilder builder, Uri serviceUri, TokenCredential tokenCredential)
    where TBuilder : IAzureClientFactoryBuilderWithCredential
{
    return builder.RegisterClientFactory<BlobServiceClient, BlobClientOptions>((options, token) => new BlobServiceClient(serviceUri, token, options));
}

is not passing down the provided TokenCredential.

Expected behavior

The provided TokenCredential will be used, maybe like this:

public static IAzureClientBuilder<BlobServiceClient, BlobClientOptions> AddBlobServiceClient<TBuilder>(this TBuilder builder, Uri serviceUri, TokenCredential tokenCredential)
    where TBuilder : IAzureClientFactoryBuilderWithCredential
{
    return builder.RegisterClientFactory<BlobServiceClient, BlobClientOptions>((options, _) => new BlobServiceClient(serviceUri, tokenCredential, options));
}

Actual behavior

The DefaultAzureCredential is always being used, which leads to unnecessary token requests, that mostly cannot be resolved and even throw exceptions when some configuration is missing.

Reproduction Steps

Add the service to the IServiceCollection like this:

services.AddAzureClients(
    config =>
    {
        config.AddBlobServiceClient(
            new Uri("<url to the storage account>"),
            new AzureCliCredential());
    });

Environment

No response

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.Service AttentionWorkflow: This issue is responsible by Azure service team.StorageStorage Service (Queues, Blobs, Files)customer-reportedIssues that are reported by GitHub users external to the Azure organization.issue-addressedWorkflow: The Azure SDK team believes it to be addressed and ready to close.questionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions