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:
parent
ecae6838b8
commit
b991e4b9c2
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue