-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathOAuth2IntrospectionExtensions.cs
More file actions
63 lines (57 loc) · 2.88 KB
/
OAuth2IntrospectionExtensions.cs
File metadata and controls
63 lines (57 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Copyright (c) Duende Software. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;
namespace Duende.AspNetCore.Authentication.OAuth2Introspection;
/// <summary>
/// Extensions for registering the OAuth 2.0 introspection authentication handler
/// </summary>
public static class OAuth2IntrospectionExtensions
{
/// <summary>
/// Adds the OAuth 2.0 introspection handler.
/// </summary>
/// <param name="builder">The builder.</param>
/// <returns></returns>
public static AuthenticationBuilder AddOAuth2Introspection(this AuthenticationBuilder builder)
=> builder.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme);
/// <summary>
/// Adds the OAuth 2.0 introspection handler.
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="authenticationScheme">The authentication scheme.</param>
/// <returns></returns>
public static AuthenticationBuilder AddOAuth2Introspection(this AuthenticationBuilder builder, string authenticationScheme)
=> builder.AddOAuth2Introspection(authenticationScheme, configureOptions: null);
/// <summary>
/// Adds the OAuth 2.0 introspection handler.
/// </summary>
/// <param name="services">The services.</param>
/// <param name="configureOptions">The configure options.</param>
/// <returns></returns>
public static AuthenticationBuilder AddOAuth2Introspection(
this AuthenticationBuilder services,
Action<OAuth2IntrospectionOptions>? configureOptions)
=> services.AddOAuth2Introspection(OAuth2IntrospectionDefaults.AuthenticationScheme, configureOptions: configureOptions);
/// <summary>
/// Adds the OAuth 2.0 introspection handler.
/// </summary>
/// <param name="builder">The builder.</param>
/// <param name="authenticationScheme">The authentication scheme.</param>
/// <param name="configureOptions">The configure options.</param>
/// <returns></returns>
public static AuthenticationBuilder AddOAuth2Introspection(
this AuthenticationBuilder builder,
string authenticationScheme,
Action<OAuth2IntrospectionOptions>? configureOptions)
{
builder.Services.AddHttpClient(OAuth2IntrospectionDefaults.BackChannelHttpClientName);
var serviceDescriptor = ServiceDescriptor
.Singleton<IPostConfigureOptions<OAuth2IntrospectionOptions>, PostConfigureOAuth2IntrospectionOptions>();
builder.Services.TryAddEnumerable(serviceDescriptor);
builder.AddScheme<OAuth2IntrospectionOptions, OAuth2IntrospectionHandler>(authenticationScheme, configureOptions);
return builder;
}
}