Fix AzureAd options validation (#23096)

This commit is contained in:
John Luo 2020-07-14 17:15:12 -07:00 committed by GitHub
parent 4db94ff4da
commit d45e6b25f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 0 deletions

View File

@ -21,6 +21,11 @@ namespace Microsoft.AspNetCore.Authentication.AzureAD.UI
public void Configure(string name, OpenIdConnectOptions options) public void Configure(string name, OpenIdConnectOptions options)
{ {
var azureADScheme = GetAzureADScheme(name); var azureADScheme = GetAzureADScheme(name);
if (azureADScheme is null)
{
return;
}
var azureADOptions = _azureADOptions.Get(azureADScheme); var azureADOptions = _azureADOptions.Get(azureADScheme);
if (name != azureADOptions.OpenIdConnectSchemeName) if (name != azureADOptions.OpenIdConnectSchemeName)
{ {

View File

@ -485,5 +485,25 @@ namespace Microsoft.AspNetCore.Authentication
Assert.NotNull(jwtOptions.Get("other")); 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"));
}
} }
} }