diff --git a/src/Microsoft.Identity.Web/WebAppExtensions/MicrosoftIdentityWebAppAuthenticationBuilderExtensions.cs b/src/Microsoft.Identity.Web/WebAppExtensions/MicrosoftIdentityWebAppAuthenticationBuilderExtensions.cs index 8492cdfd8..6e3fce4b1 100644 --- a/src/Microsoft.Identity.Web/WebAppExtensions/MicrosoftIdentityWebAppAuthenticationBuilderExtensions.cs +++ b/src/Microsoft.Identity.Web/WebAppExtensions/MicrosoftIdentityWebAppAuthenticationBuilderExtensions.cs @@ -317,7 +317,7 @@ s.ServiceKey is null && mergedOptions.PreserveAuthority = preserveAuthority; if (mergedOptions.ExtraQueryParameters != null) { - options.MetadataAddress = mergedOptions.Authority + "/.well-known/openid-configuration?" + string.Join("&", mergedOptions.ExtraQueryParameters.Select(p => $"{p.Key}={p.Value}")); + mergedOptions.MetadataAddress = mergedOptions.Authority + "/.well-known/openid-configuration?" + string.Join("&", mergedOptions.ExtraQueryParameters.Select(p => $"{p.Key}={p.Value}")); } } diff --git a/tests/Microsoft.Identity.Web.Test/WebAppExtensionsTests.cs b/tests/Microsoft.Identity.Web.Test/WebAppExtensionsTests.cs index e508e702e..dca933c42 100644 --- a/tests/Microsoft.Identity.Web.Test/WebAppExtensionsTests.cs +++ b/tests/Microsoft.Identity.Web.Test/WebAppExtensionsTests.cs @@ -183,6 +183,38 @@ public void AddMicrosoftIdentityWebApp_WithConfigActionParameters(bool subscribe AddMicrosoftIdentityWebApp_TestSubscribesToDiagnostics(services, diagnosticsMock, subscribeToDiagnostics); } + [Fact] + public Task AddMicrosoftIdentityWebApp_WithConfigAuthority_TestCorrectMetadataAddress() + { + // Arrange + string authority = "https://login.microsoftonline.com/some-tenant-id/v2.0"; + string appId = "some-client-id"; + string expectedMetadataAddress = $"{authority}/.well-known/openid-configuration?appId={appId}"; + var configMock = Substitute.For(); + configMock.Configure().GetSection(ConfigSectionName).Returns(_configSection); + + var services = new ServiceCollection() + .AddSingleton(configMock) + .PostConfigure(OidcScheme, (options) => + { + options.Authority = authority; + options.ExtraQueryParameters = new Dictionary + { + {"appId", appId} + }; + }); + + // Act + services.AddAuthentication() + .AddMicrosoftIdentityWebApp(configMock, ConfigSectionName, OidcScheme, CookieScheme, subscribeToOpenIdConnectMiddlewareDiagnosticsEvents: false); + var provider = services.BuildServiceProvider(); + var providedOptions = provider.GetRequiredService>().Get(OidcScheme); + + // Assert + Assert.Equal(expectedMetadataAddress, providedOptions.MetadataAddress); + return Task.CompletedTask; + } + [Fact] public async Task AddMicrosoftIdentityWebApp_WithConfigNameParameters_TestRedirectToIdentityProviderEvent() {