Fix AzureAd options validation (#13480)

* Skip getting AzureAdOptions for not AzureADUi Cookies scheme #13311 (#13327)

* Also check Azure Jwt options for #13311
This commit is contained in:
Chris Ross 2019-08-27 15:59:08 -07:00 committed by GitHub
parent ecae6838b8
commit b991e4b9c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 0 deletions

View File

@ -21,6 +21,11 @@ namespace Microsoft.AspNetCore.Authentication.AzureAD.UI
public void Configure(string name, CookieAuthenticationOptions options)
{
var AzureADScheme = GetAzureADScheme(name);
if (AzureADScheme is null)
{
return;
}
var AzureADOptions = _AzureADOptions.Get(AzureADScheme);
if (name != AzureADOptions.CookieSchemeName)
{

View File

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

View File

@ -268,6 +268,22 @@ namespace Microsoft.AspNetCore.Authentication
Assert.Contains(expectedMessage, exception.Failures);
}
[Fact]
public void AddAzureAD_SkipsOptionsValidationForNonAzureCookies()
{
var services = new ServiceCollection();
services.AddSingleton<ILoggerFactory>(new NullLoggerFactory());
services.AddAuthentication()
.AddAzureAD(o => { })
.AddCookie("other");
var provider = services.BuildServiceProvider();
var cookieAuthOptions = provider.GetService<IOptionsMonitor<CookieAuthenticationOptions>>();
Assert.NotNull(cookieAuthOptions.Get("other"));
}
[Fact]
public void AddAzureADBearer_AddsAllAuthenticationHandlers()
{
@ -453,5 +469,21 @@ namespace Microsoft.AspNetCore.Authentication
Assert.Contains(expectedMessage, exception.Failures);
}
[Fact]
public void AddAzureADBearer_SkipsOptionsValidationForNonAzureCookies()
{
var services = new ServiceCollection();
services.AddSingleton<ILoggerFactory>(new NullLoggerFactory());
services.AddAuthentication()
.AddAzureADBearer(o => { })
.AddJwtBearer("other", o => { });
var provider = services.BuildServiceProvider();
var jwtOptions = provider.GetService<IOptionsMonitor<JwtBearerOptions>>();
Assert.NotNull(jwtOptions.Get("other"));
}
}
}