@@ -17,7 +17,7 @@ public static class AuthenticationBuilderExtensions
1717 /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
1818 /// </returns>
1919 public static AuthenticationBuilder AddSecurityKey ( this AuthenticationBuilder builder )
20- => builder . AddSecurityKey ( SecurityKeyAuthenticationDefaults . AuthenticationScheme ) ;
20+ => builder . AddSecurityKey ( authenticationScheme : SecurityKeyAuthenticationDefaults . AuthenticationScheme , displayName : null , configureOptions : null ) ;
2121
2222 /// <summary>
2323 /// Registers security API key authentication using a specified scheme.
@@ -28,7 +28,7 @@ public static AuthenticationBuilder AddSecurityKey(this AuthenticationBuilder bu
2828 /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
2929 /// </returns>
3030 public static AuthenticationBuilder AddSecurityKey ( this AuthenticationBuilder builder , string authenticationScheme )
31- => builder . AddSecurityKey ( authenticationScheme , configureOptions : null ) ;
31+ => builder . AddSecurityKey ( authenticationScheme : authenticationScheme , displayName : null , configureOptions : null ) ;
3232
3333 /// <summary>
3434 /// Registers security API key authentication using the default scheme and allows configuration of options.
@@ -40,7 +40,7 @@ public static AuthenticationBuilder AddSecurityKey(this AuthenticationBuilder bu
4040 /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
4141 /// </returns>
4242 public static AuthenticationBuilder AddSecurityKey ( this AuthenticationBuilder builder , Action < SecurityKeyAuthenticationSchemeOptions > ? configureOptions )
43- => builder . AddSecurityKey ( SecurityKeyAuthenticationDefaults . AuthenticationScheme , configureOptions ) ;
43+ => builder . AddSecurityKey ( authenticationScheme : SecurityKeyAuthenticationDefaults . AuthenticationScheme , displayName : null , configureOptions : configureOptions ) ;
4444
4545 /// <summary>
4646 /// Registers security API key authentication using a specified scheme and allows configuration of options.
@@ -52,7 +52,7 @@ public static AuthenticationBuilder AddSecurityKey(this AuthenticationBuilder bu
5252 /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
5353 /// </returns>
5454 public static AuthenticationBuilder AddSecurityKey ( this AuthenticationBuilder builder , string authenticationScheme , Action < SecurityKeyAuthenticationSchemeOptions > ? configureOptions )
55- => builder . AddSecurityKey ( authenticationScheme , displayName : null , configureOptions : configureOptions ) ;
55+ => builder . AddSecurityKey ( authenticationScheme : authenticationScheme , displayName : null , configureOptions : configureOptions ) ;
5656
5757 /// <summary>
5858 /// Registers security API key authentication using a specified scheme, display name, and configuration options.
@@ -68,10 +68,114 @@ public static AuthenticationBuilder AddSecurityKey(this AuthenticationBuilder bu
6868 /// Thrown when <paramref name="builder"/> is <c>null</c>.
6969 /// </exception>
7070 public static AuthenticationBuilder AddSecurityKey ( this AuthenticationBuilder builder , string authenticationScheme , string ? displayName , Action < SecurityKeyAuthenticationSchemeOptions > ? configureOptions )
71+ => builder . AddSecurityKey < SecurityKeyValidator , SecurityKeyExtractor > ( authenticationScheme , displayName , configureOptions ) ;
72+
73+ /// <summary>
74+ /// Registers security API key authentication using a specified validator type.
75+ /// </summary>
76+ /// <typeparam name="TValidator">The type of the validator implementing <see cref="ISecurityKeyValidator"/>.</typeparam>
77+ /// <param name="builder">The <see cref="AuthenticationBuilder"/> to configure.</param>
78+ /// <returns>
79+ /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
80+ /// </returns>
81+ public static AuthenticationBuilder AddSecurityKey < TValidator > ( this AuthenticationBuilder builder )
82+ where TValidator : class , ISecurityKeyValidator
83+ => builder . AddSecurityKey < TValidator , SecurityKeyExtractor > ( authenticationScheme : SecurityKeyAuthenticationDefaults . AuthenticationScheme , displayName : null , configureOptions : null ) ;
84+
85+ /// <summary>
86+ /// Registers security API key authentication using a specified validator type and scheme.
87+ /// </summary>
88+ /// <typeparam name="TValidator">The type of the validator implementing <see cref="ISecurityKeyValidator"/>.</typeparam>
89+ /// <param name="builder">The <see cref="AuthenticationBuilder"/> to configure.</param>
90+ /// <param name="authenticationScheme">The name of the authentication scheme to use.</param>
91+ /// <returns>
92+ /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
93+ /// </returns>
94+ public static AuthenticationBuilder AddSecurityKey < TValidator > ( this AuthenticationBuilder builder , string authenticationScheme )
95+ where TValidator : class , ISecurityKeyValidator
96+ => builder . AddSecurityKey < TValidator , SecurityKeyExtractor > ( authenticationScheme : authenticationScheme , displayName : null , configureOptions : null ) ;
97+
98+ /// <summary>
99+ /// Registers security API key authentication using a specified validator type and configuration options.
100+ /// </summary>
101+ /// <typeparam name="TValidator">The type of the validator implementing <see cref="ISecurityKeyValidator"/>.</typeparam>
102+ /// <param name="builder">The <see cref="AuthenticationBuilder"/> to configure.</param>
103+ /// <param name="configureOptions">A delegate to configure <see cref="SecurityKeyAuthenticationSchemeOptions"/>.</param>
104+ /// <returns>
105+ /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
106+ /// </returns>
107+ public static AuthenticationBuilder AddSecurityKey < TValidator > ( this AuthenticationBuilder builder , Action < SecurityKeyAuthenticationSchemeOptions > ? configureOptions )
108+ where TValidator : class , ISecurityKeyValidator
109+ => builder . AddSecurityKey < TValidator , SecurityKeyExtractor > ( authenticationScheme : SecurityKeyAuthenticationDefaults . AuthenticationScheme , displayName : null , configureOptions : configureOptions ) ;
110+
111+ /// <summary>
112+ /// Registers security API key authentication using specified validator and extractor types.
113+ /// </summary>
114+ /// <typeparam name="TValidator">The type of the validator implementing <see cref="ISecurityKeyValidator"/>.</typeparam>
115+ /// <typeparam name="TExtractor">The type of the extractor implementing <see cref="ISecurityKeyExtractor"/>.</typeparam>
116+ /// <param name="builder">The <see cref="AuthenticationBuilder"/> to configure.</param>
117+ /// <returns>
118+ /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
119+ /// </returns>
120+ public static AuthenticationBuilder AddSecurityKey < TValidator , TExtractor > ( this AuthenticationBuilder builder )
121+ where TValidator : class , ISecurityKeyValidator
122+ where TExtractor : class , ISecurityKeyExtractor
123+ => builder . AddSecurityKey < TValidator , TExtractor > ( authenticationScheme : SecurityKeyAuthenticationDefaults . AuthenticationScheme , displayName : null , configureOptions : null ) ;
124+
125+ /// <summary>
126+ /// Registers security API key authentication using specified validator and extractor types and a scheme.
127+ /// </summary>
128+ /// <typeparam name="TValidator">The type of the validator implementing <see cref="ISecurityKeyValidator"/>.</typeparam>
129+ /// <typeparam name="TExtractor">The type of the extractor implementing <see cref="ISecurityKeyExtractor"/>.</typeparam>
130+ /// <param name="builder">The <see cref="AuthenticationBuilder"/> to configure.</param>
131+ /// <param name="authenticationScheme">The name of the authentication scheme to use.</param>
132+ /// <returns>
133+ /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
134+ /// </returns>
135+ public static AuthenticationBuilder AddSecurityKey < TValidator , TExtractor > ( this AuthenticationBuilder builder , string authenticationScheme )
136+ where TValidator : class , ISecurityKeyValidator
137+ where TExtractor : class , ISecurityKeyExtractor
138+ => builder . AddSecurityKey < TValidator , TExtractor > ( authenticationScheme : authenticationScheme , displayName : null , configureOptions : null ) ;
139+
140+ /// <summary>
141+ /// Registers security API key authentication using specified validator and extractor types and configuration options.
142+ /// </summary>
143+ /// <typeparam name="TValidator">The type of the validator implementing <see cref="ISecurityKeyValidator"/>.</typeparam>
144+ /// <typeparam name="TExtractor">The type of the extractor implementing <see cref="ISecurityKeyExtractor"/>.</typeparam>
145+ /// <param name="builder">The <see cref="AuthenticationBuilder"/> to configure.</param>
146+ /// <param name="configureOptions">A delegate to configure <see cref="SecurityKeyAuthenticationSchemeOptions"/>.</param>
147+ /// <returns>
148+ /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
149+ /// </returns>
150+ public static AuthenticationBuilder AddSecurityKey < TValidator , TExtractor > ( this AuthenticationBuilder builder , Action < SecurityKeyAuthenticationSchemeOptions > ? configureOptions )
151+ where TValidator : class , ISecurityKeyValidator
152+ where TExtractor : class , ISecurityKeyExtractor
153+ => builder . AddSecurityKey < TValidator , TExtractor > ( authenticationScheme : SecurityKeyAuthenticationDefaults . AuthenticationScheme , displayName : null , configureOptions : configureOptions ) ;
154+
155+ /// <summary>
156+ /// Registers security API key authentication using specified validator and extractor types, a scheme, a display name, and configuration options.
157+ /// </summary>
158+ /// <typeparam name="TValidator">The type of the validator implementing <see cref="ISecurityKeyValidator"/>.</typeparam>
159+ /// <typeparam name="TExtractor">The type of the extractor implementing <see cref="ISecurityKeyExtractor"/>.</typeparam>
160+ /// <param name="builder">The <see cref="AuthenticationBuilder"/> to configure.</param>
161+ /// <param name="authenticationScheme">The name of the authentication scheme to use.</param>
162+ /// <param name="displayName">A display name for the authentication handler, used for UI or logging purposes.</param>
163+ /// <param name="configureOptions">A delegate to configure <see cref="SecurityKeyAuthenticationSchemeOptions"/>.</param>
164+ /// <returns>
165+ /// The <see cref="AuthenticationBuilder"/> instance for chaining further authentication configuration.
166+ /// </returns>
167+ /// <exception cref="ArgumentNullException">
168+ /// Thrown when <paramref name="builder"/> is <c>null</c>.
169+ /// </exception>
170+ public static AuthenticationBuilder AddSecurityKey < TValidator , TExtractor > ( this AuthenticationBuilder builder , string authenticationScheme , string ? displayName , Action < SecurityKeyAuthenticationSchemeOptions > ? configureOptions )
171+ where TValidator : class , ISecurityKeyValidator
172+ where TExtractor : class , ISecurityKeyExtractor
71173 {
72174 ArgumentNullException . ThrowIfNull ( builder ) ;
73175
74176 builder . Services . AddOptions < SecurityKeyAuthenticationSchemeOptions > ( authenticationScheme ) ;
177+ builder . Services . AddSecurityKey < TValidator , TExtractor > ( ) ;
178+
75179 return builder . AddScheme < SecurityKeyAuthenticationSchemeOptions , SecurityKeyAuthenticationHandler > ( authenticationScheme , displayName , configureOptions ) ;
76180 }
77181}
0 commit comments