Skip to content

Commit 70151da

Browse files
committed
fix: fix PostConfigureOAuth2IntrospectionOptions with named options
1 parent 77ecd17 commit 70151da

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/OAuth2IntrospectionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public static AuthenticationBuilder AddOAuth2Introspection(this AuthenticationBu
5050
/// <returns></returns>
5151
public static AuthenticationBuilder AddOAuth2Introspection(this AuthenticationBuilder builder, string authenticationScheme, Action<OAuth2IntrospectionOptions> configureOptions)
5252
{
53-
builder.Services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName);
54-
55-
builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton<IPostConfigureOptions<OAuth2IntrospectionOptions>, PostConfigureOAuth2IntrospectionOptions>());
53+
builder.Services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName);
54+
55+
builder.Services.Add(ServiceDescriptor.Singleton<IPostConfigureOptions<OAuth2IntrospectionOptions>>(p => ActivatorUtilities.CreateInstance<PostConfigureOAuth2IntrospectionOptions>(p, authenticationScheme)));
5656
return builder.AddScheme<OAuth2IntrospectionOptions, OAuth2IntrospectionHandler>(authenticationScheme, configureOptions);
5757
}
5858
}

src/PostConfigureOAuth2IntrospectionOptions.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,24 @@ namespace IdentityModel.AspNetCore.OAuth2Introspection
1313
{
1414
internal class PostConfigureOAuth2IntrospectionOptions : IPostConfigureOptions<OAuth2IntrospectionOptions>
1515
{
16+
private readonly string _name;
1617
private readonly IDistributedCache _cache;
1718
private readonly IHttpClientFactory _httpClientFactory;
1819

19-
public PostConfigureOAuth2IntrospectionOptions(IHttpClientFactory httpClientFactory, IDistributedCache cache = null)
20+
public PostConfigureOAuth2IntrospectionOptions(string name, IHttpClientFactory httpClientFactory, IDistributedCache cache = null)
2021
{
22+
_name = name;
2123
_cache = cache;
2224
_httpClientFactory = httpClientFactory;
2325
}
2426

2527
public void PostConfigure(string name, OAuth2IntrospectionOptions options)
2628
{
29+
if (name != _name)
30+
{
31+
return;
32+
}
33+
2734
options.Validate();
2835

2936
if (options.EnableCaching && _cache == null)

0 commit comments

Comments
 (0)