From d45e6b25f47c5349736bcfffc19820e60fe933d7 Mon Sep 17 00:00:00 2001 From: John Luo <johluo@microsoft.com> Date: Tue, 14 Jul 2020 17:15:12 -0700 Subject: [PATCH] Fix AzureAd options validation (#23096) --- ...zureADOpenIdConnectOptionsConfiguration.cs | 5 +++++ ...eADAuthenticationBuilderExtensionsTests.cs | 20 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/Azure/AzureAD/Authentication.AzureAD.UI/src/AzureADOpenIdConnectOptionsConfiguration.cs b/src/Azure/AzureAD/Authentication.AzureAD.UI/src/AzureADOpenIdConnectOptionsConfiguration.cs index a991620aae3..9b5be26438f 100644 --- a/src/Azure/AzureAD/Authentication.AzureAD.UI/src/AzureADOpenIdConnectOptionsConfiguration.cs +++ b/src/Azure/AzureAD/Authentication.AzureAD.UI/src/AzureADOpenIdConnectOptionsConfiguration.cs @@ -21,6 +21,11 @@ namespace Microsoft.AspNetCore.Authentication.AzureAD.UI public void Configure(string name, OpenIdConnectOptions options) { var azureADScheme = GetAzureADScheme(name); + if (azureADScheme is null) + { + return; + } + var azureADOptions = _azureADOptions.Get(azureADScheme); if (name != azureADOptions.OpenIdConnectSchemeName) { diff --git a/src/Azure/AzureAD/Authentication.AzureAD.UI/test/AzureADAuthenticationBuilderExtensionsTests.cs b/src/Azure/AzureAD/Authentication.AzureAD.UI/test/AzureADAuthenticationBuilderExtensionsTests.cs index 07c0583c32b..6a31d3477ec 100644 --- a/src/Azure/AzureAD/Authentication.AzureAD.UI/test/AzureADAuthenticationBuilderExtensionsTests.cs +++ b/src/Azure/AzureAD/Authentication.AzureAD.UI/test/AzureADAuthenticationBuilderExtensionsTests.cs @@ -485,5 +485,25 @@ namespace Microsoft.AspNetCore.Authentication Assert.NotNull(jwtOptions.Get("other")); } + + [Fact] + public void AddAzureAD_SkipsOptionsValidationForNonAzureOpenIdConnect() + { + var services = new ServiceCollection(); + services.AddSingleton<ILoggerFactory>(new NullLoggerFactory()); + + services.AddAuthentication() + .AddAzureAD(o => { }) + .AddOpenIdConnect("other", null, o => + { + o.ClientId = "ClientId"; + o.Authority = "https://authority.com"; + }); + + var provider = services.BuildServiceProvider(); + var openIdConnectOptions = provider.GetService<IOptionsMonitor<OpenIdConnectOptions>>(); + + Assert.NotNull(openIdConnectOptions.Get("other")); + } } } -- GitLab