Skip to content

Commit 767a50b

Browse files
authored
[IDP-623] Fix auth scheme not propagating. (#32)
1 parent 49b4add commit 767a50b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/Workleap.AspNetCore.Authentication.ClientCredentialsGrant/AuthenticationBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static AuthenticationBuilder AddClientCredentials(this AuthenticationBuil
3737
configSection.Bind(options);
3838
});
3939

40-
builder.AddJwtBearer(ClientCredentialsDefaults.AuthenticationScheme, configureOptions);
40+
builder.AddJwtBearer(authScheme, configureOptions);
4141

4242
var tokenHandlerNamedConfigureOptionsAlreadyAdded = builder.Services.Any(x => IsDescriptorOfJwtBearerOptionsValidator(x, authScheme));
4343
if (!tokenHandlerNamedConfigureOptionsAlreadyAdded)

src/Workleap.Authentication.ClientCredentialsGrant.Tests/AuthenticationBuilderExtensionsTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ public void GivenAnAuthenticationBuilder_WhenConfigsArePresent_ThenOptionsAreSet
133133
Assert.Throws<OptionsValidationException>(() => sp.GetRequiredService<IOptionsSnapshot<JwtBearerOptions>>().Get(ClientCredentialsDefaults.AuthenticationScheme));
134134
}
135135

136+
[Fact]
137+
public void GivenAnAuthenticationBuilderWithACustomAuthScheme_WhenAddClientCredentials_ThenAuthSchemeIsSet()
138+
{
139+
var services = new ServiceCollection();
140+
var configuration = new ConfigurationBuilder().Build();
141+
services.AddSingleton<IConfiguration>(configuration);
142+
143+
services.AddAuthentication().AddClientCredentials("CustomScheme", options =>
144+
{
145+
options.Audience = "audience";
146+
options.Authority = "https://identity.local";
147+
});
148+
149+
var sp = services.BuildServiceProvider();
150+
var jwtBearerOptions = sp.GetRequiredService<IOptionsSnapshot<JwtBearerOptions>>().Get("CustomScheme");
151+
152+
Assert.NotNull(jwtBearerOptions);
153+
}
154+
136155
[Fact]
137156
public void GivenNoAuthenticationBuilder_WhenCalling_ThrowArgumentNullException()
138157
{

0 commit comments

Comments
 (0)