Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public AzureADCookieOptionsConfiguration(IOptions<AzureADSchemeOptions> schemeOp
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public AzureADJwtBearerOptionsConfiguration(
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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,22 @@ public void AddAzureAD_ThrowsWhenInstanceIsNotSet()
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()
{
Expand Down Expand Up @@ -453,5 +469,21 @@ public void AddAzureADBearer_ThrowsWhenInstanceIsNotSet()

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"));
}
}
}