Skip to content

Commit

Permalink
[IDP-623] Fix auth scheme not propagating. (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zav authored Sep 28, 2023
1 parent 49b4add commit 767a50b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static AuthenticationBuilder AddClientCredentials(this AuthenticationBuil
configSection.Bind(options);
});

builder.AddJwtBearer(ClientCredentialsDefaults.AuthenticationScheme, configureOptions);
builder.AddJwtBearer(authScheme, configureOptions);

var tokenHandlerNamedConfigureOptionsAlreadyAdded = builder.Services.Any(x => IsDescriptorOfJwtBearerOptionsValidator(x, authScheme));
if (!tokenHandlerNamedConfigureOptionsAlreadyAdded)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,25 @@ public void GivenAnAuthenticationBuilder_WhenConfigsArePresent_ThenOptionsAreSet
Assert.Throws<OptionsValidationException>(() => sp.GetRequiredService<IOptionsSnapshot<JwtBearerOptions>>().Get(ClientCredentialsDefaults.AuthenticationScheme));
}

[Fact]
public void GivenAnAuthenticationBuilderWithACustomAuthScheme_WhenAddClientCredentials_ThenAuthSchemeIsSet()
{
var services = new ServiceCollection();
var configuration = new ConfigurationBuilder().Build();
services.AddSingleton<IConfiguration>(configuration);

services.AddAuthentication().AddClientCredentials("CustomScheme", options =>
{
options.Audience = "audience";
options.Authority = "https://identity.local";
});

var sp = services.BuildServiceProvider();
var jwtBearerOptions = sp.GetRequiredService<IOptionsSnapshot<JwtBearerOptions>>().Get("CustomScheme");

Assert.NotNull(jwtBearerOptions);
}

[Fact]
public void GivenNoAuthenticationBuilder_WhenCalling_ThrowArgumentNullException()
{
Expand Down

0 comments on commit 767a50b

Please sign in to comment.