Skip to content

No auth component rendered when using IValueProvider in metadata #1120

@SrChronus

Description

@SrChronus

Describe the bug

When setting up the below one would expect, based on the xdoc, that values provided through the WithMetaData using IValueProvider will be available for the component. However, they are not. I believe the issue is in https://github.com/CommunityToolkit/Aspire/blob/main/src/CommunityToolkit.Aspire.Hosting.Dapr/DaprDistributedApplicationLifecycleHook.cs#L662

which will only render the auth section if anything was a secret. So without adding a dummy secret it won't be able to use the IValueProvider values.

/// <summary>
/// Adds a value provider as metadata to the Dapr component that will be resolved at runtime.
/// </summary>
/// <param name="builder">The resource builder for the Dapr component being configured.</param>
/// <param name="name">The name of the metadata property to add to the Dapr component configuration.</param>
/// <param name="valueProvider">The value provider (e.g., EndpointReference, ConnectionStringReference) whose value will be resolved at runtime.
/// The provider's value is stored as an environment variable and referenced through Dapr's secret key reference mechanism.</param>
/// <returns>The resource builder instance.</returns>
/// <remarks>
/// This method enables dynamic configuration of Dapr components by:
/// <list type="bullet">
/// <item>Creating a unique environment variable name based on the component and metadata names</item>
/// <item>Storing the value provider reference for runtime resolution</item>
/// <item>Configuring the metadata to use a secretKeyRef pointing to the environment variable</item>
/// </list>
/// The environment variable name format is: {COMPONENT_NAME}_{METADATA_NAME} (uppercased, hyphens replaced with underscores).
/// This approach allows for secure injection of dynamic values like endpoint URLs or connection strings that are only known at runtime.
/// </remarks>
/// <example>

Regression

No response

Steps to reproduce

var storage = builder.AddAzureStorage("so0meName").RunAsEmulator();
var container = storage.AddBlobContainer("bla");

var comp = builder.AddDaprComponent("blbala", "state.azure.blobstorage")
    .WithMetadata("endpoint", container.Resource.Parent.UriExpression)
        .WithMetadata("accountName", "devstoreaccount1")
        .WithMetadata("accountKey", "key")
        .WithMetadata("containerName", "bla")
    .WaitFor(container);

Expected behavior

The whole AddMetaData overload seems to be designed to be able to insert these kind of connection settings, so I would expect that to work out of the box

Screenshots

No response

IDE and version

Other

IDE version

No response

Nuget packages

<PackageReference Include="Aspire.Azure.Storage.Blobs" Version="13.1.0" />
        <PackageReference Include="Aspire.Hosting" Version="13.1.0" />
        <PackageReference Include="Aspire.Hosting.AppHost" Version="13.1.0" />
        <PackageReference Include="Aspire.Hosting.Azure.CosmosDB" Version="13.1.0" />
        <PackageReference Include="Aspire.Hosting.Azure.Storage" Version="13.1.0" />
        <PackageReference Include="Aspire.Hosting.SqlServer" Version="13.1.0" />
        <PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
        <PackageReference Include="CommunityToolkit.Aspire.Hosting.Dapr" Version="13.0.0" />

Additional context

No response

Help us help you

Yes, I'd like to be assigned to work on this item

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions