1
- using Fido2NetLib ;
1
+ using System . ComponentModel ;
2
+
3
+ using Fido2NetLib ;
2
4
3
5
using Microsoft . Extensions . Configuration ;
4
6
using Microsoft . Extensions . DependencyInjection . Extensions ;
7
9
8
10
namespace Microsoft . Extensions . DependencyInjection ;
9
11
12
+ /// <summary>
13
+ /// Extension methods for configuring FIDO2 services in an <see cref="IServiceCollection"/>.
14
+ /// </summary>
10
15
public static class Fido2NetLibBuilderExtensions
11
16
{
17
+ /// <summary>
18
+ /// Adds FIDO2 services to the specified service collection using configuration from an IConfiguration instance.
19
+ /// </summary>
20
+ /// <param name="services">The service collection to add FIDO2 services to.</param>
21
+ /// <param name="configuration">The configuration containing FIDO2 settings.</param>
22
+ /// <returns>An <see cref="IFido2NetLibBuilder"/> for configuring additional FIDO2 services.</returns>
23
+ /// <remarks>
24
+ /// This method registers the core FIDO2 services:
25
+ /// <list type="bullet">
26
+ /// <item><description><see cref="IFido2"/> as a scoped service</description></item>
27
+ /// <item><description><see cref="Fido2Configuration"/> as a singleton from configuration</description></item>
28
+ /// <item><description><see cref="ISystemClock"/> as a singleton (if not already registered)</description></item>
29
+ /// </list>
30
+ /// No metadata service is registered by default. Use the returned builder to add metadata services.
31
+ /// </remarks>
32
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="services"/> or <paramref name="configuration"/> is null.</exception>
12
33
public static IFido2NetLibBuilder AddFido2 ( this IServiceCollection services , IConfiguration configuration )
13
34
{
14
35
services . Configure < Fido2Configuration > ( configuration ) ;
@@ -22,6 +43,22 @@ public static IFido2NetLibBuilder AddFido2(this IServiceCollection services, ICo
22
43
return new Fido2NetLibBuilder ( services ) ;
23
44
}
24
45
46
+ /// <summary>
47
+ /// Adds FIDO2 services to the specified service collection using a configuration action.
48
+ /// </summary>
49
+ /// <param name="services">The service collection to add FIDO2 services to.</param>
50
+ /// <param name="setupAction">An action to configure the FIDO2 configuration options.</param>
51
+ /// <returns>An <see cref="IFido2NetLibBuilder"/> for configuring additional FIDO2 services.</returns>
52
+ /// <remarks>
53
+ /// This method registers the core FIDO2 services:
54
+ /// <list type="bullet">
55
+ /// <item><description><see cref="IFido2"/> as a scoped service</description></item>
56
+ /// <item><description><see cref="Fido2Configuration"/> as a singleton from the setup action</description></item>
57
+ /// <item><description><see cref="ISystemClock"/> as a singleton (if not already registered)</description></item>
58
+ /// </list>
59
+ /// No metadata service is registered by default. Use the returned builder to add metadata services.
60
+ /// </remarks>
61
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="services"/> or <paramref name="setupAction"/> is null.</exception>
25
62
public static IFido2NetLibBuilder AddFido2 ( this IServiceCollection services , Action < Fido2Configuration > setupAction )
26
63
{
27
64
services . Configure ( setupAction ) ;
@@ -35,20 +72,56 @@ public static IFido2NetLibBuilder AddFido2(this IServiceCollection services, Act
35
72
return new Fido2NetLibBuilder ( services ) ;
36
73
}
37
74
75
+ /// <summary>
76
+ /// Adds a custom metadata service implementation to the FIDO2 builder.
77
+ /// </summary>
78
+ /// <typeparam name="T">The type of metadata service to add. Must implement <see cref="IMetadataService"/>.</typeparam>
79
+ /// <param name="builder">The FIDO2 builder instance.</param>
80
+ /// <returns>The <see cref="IFido2NetLibBuilder"/> for method chaining.</returns>
81
+ /// <remarks>
82
+ /// This method registers the specified metadata service implementation as a scoped service,
83
+ /// replacing any previously registered <see cref="IMetadataService"/>.
84
+ /// </remarks>
85
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is null.</exception>
38
86
public static IFido2NetLibBuilder AddMetadataService < T > ( this IFido2NetLibBuilder builder )
39
87
where T : class , IMetadataService
40
88
{
41
89
builder . Services . AddScoped < IMetadataService , T > ( ) ;
42
90
return builder ;
43
91
}
44
92
45
-
93
+ /// <summary>
94
+ /// Adds the distributed cache-based metadata service to the FIDO2 builder.
95
+ /// </summary>
96
+ /// <param name="builder">The FIDO2 builder instance.</param>
97
+ /// <returns>The <see cref="IFido2NetLibBuilder"/> for method chaining.</returns>
98
+ /// <remarks>
99
+ /// This method registers the <see cref="DistributedCacheMetadataService"/> as a scoped service.
100
+ /// This service provides caching capabilities for metadata using both memory and distributed cache.
101
+ /// Ensure that memory cache and distributed cache services are registered before calling this method.
102
+ /// Use the returned builder to add metadata repositories.
103
+ /// </remarks>
104
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is null.</exception>
46
105
public static IFido2NetLibBuilder AddCachedMetadataService ( this IFido2NetLibBuilder builder )
47
106
{
48
107
builder . Services . AddScoped < IMetadataService , DistributedCacheMetadataService > ( ) ;
49
108
return builder ;
50
109
}
51
-
110
+
111
+ /// <summary>
112
+ /// Adds a file system-based metadata repository to the FIDO2 builder.
113
+ /// </summary>
114
+ /// <param name="builder">The FIDO2 builder instance.</param>
115
+ /// <param name="directoryPath">The directory path containing metadata statement JSON files.</param>
116
+ /// <returns>The <see cref="IFido2NetLibBuilder"/> for method chaining.</returns>
117
+ /// <remarks>
118
+ /// This method registers a <see cref="FileSystemMetadataRepository"/> as a scoped service.
119
+ /// The repository loads metadata statements from JSON files in the specified directory.
120
+ /// Each file should contain a valid metadata statement JSON document.
121
+ /// This is typically used for development, testing, or offline scenarios.
122
+ /// </remarks>
123
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> or <paramref name="directoryPath"/> is null.</exception>
124
+ /// <exception cref="DirectoryNotFoundException">Thrown when the specified directory does not exist at runtime.</exception>
52
125
public static IFido2NetLibBuilder AddFileSystemMetadataRepository ( this IFido2NetLibBuilder builder , string directoryPath )
53
126
{
54
127
builder . Services . AddScoped < IMetadataRepository , FileSystemMetadataRepository > ( provider =>
@@ -59,6 +132,21 @@ public static IFido2NetLibBuilder AddFileSystemMetadataRepository(this IFido2Net
59
132
return builder ;
60
133
}
61
134
135
+ /// <summary>
136
+ /// DO NOT USE IN PRODUCTION: Adds a conformance metadata repository to the FIDO2 builder for FIDO Alliance conformance testing.
137
+ /// </summary>
138
+ /// <param name="builder">The FIDO2 builder instance.</param>
139
+ /// <param name="client">Optional HTTP client to use for requests. If null, a default client will be created.</param>
140
+ /// <param name="origin">The origin URL for conformance testing requests.</param>
141
+ /// <returns>The <see cref="IFido2NetLibBuilder"/> for method chaining.</returns>
142
+ /// <remarks>
143
+ /// This method registers a <see cref="ConformanceMetadataRepository"/> as a scoped service.
144
+ /// This repository is specifically designed for FIDO Alliance conformance testing and fetches
145
+ /// metadata from the conformance testing endpoints. It combines multiple metadata sources
146
+ /// into a single BLOB for comprehensive testing scenarios.
147
+ /// </remarks>
148
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is null.</exception>
149
+ [ EditorBrowsable ( EditorBrowsableState . Never ) ]
62
150
public static IFido2NetLibBuilder AddConformanceMetadataRepository (
63
151
this IFido2NetLibBuilder builder ,
64
152
HttpClient client = null ,
@@ -71,7 +159,24 @@ public static IFido2NetLibBuilder AddConformanceMetadataRepository(
71
159
72
160
return builder ;
73
161
}
74
-
162
+
163
+ /// <summary>
164
+ /// Adds the official FIDO Alliance Metadata Service (MDS) repository to the FIDO2 builder.
165
+ /// </summary>
166
+ /// <param name="builder">The FIDO2 builder instance.</param>
167
+ /// <param name="clientBuilder">Optional action to configure the HTTP client used for MDS requests.</param>
168
+ /// <returns>The <see cref="IFido2NetLibBuilder"/> for method chaining.</returns>
169
+ /// <remarks>
170
+ /// This method registers a <see cref="Fido2MetadataServiceRepository"/> as a scoped service
171
+ /// and configures an HTTP client specifically for communicating with the FIDO Alliance MDS v3
172
+ /// endpoint at https://mds3.fidoalliance.org/. The repository fetches and validates
173
+ /// JWT-signed metadata BLOBs containing authenticator metadata and certification status.
174
+ ///
175
+ /// The HTTP client is registered with a specific name and can be further configured
176
+ /// using the optional <paramref name="clientBuilder"/> action (e.g., for adding authentication,
177
+ /// custom headers, or timeout settings).
178
+ /// </remarks>
179
+ /// <exception cref="ArgumentNullException">Thrown when <paramref name="builder"/> is null.</exception>
75
180
public static IFido2NetLibBuilder AddFidoMetadataRepository ( this IFido2NetLibBuilder builder , Action < IHttpClientBuilder > clientBuilder = null )
76
181
{
77
182
var httpClientBuilder = builder . Services . AddHttpClient ( nameof ( Fido2MetadataServiceRepository ) , client =>
@@ -88,11 +193,17 @@ public static IFido2NetLibBuilder AddFidoMetadataRepository(this IFido2NetLibBui
88
193
}
89
194
}
90
195
196
+ /// <summary>
197
+ /// Provides a builder interface for configuring FIDO2 services.
198
+ /// </summary>
91
199
public interface IFido2NetLibBuilder
92
200
{
93
201
IServiceCollection Services { get ; }
94
202
}
95
203
204
+ /// <summary>
205
+ /// Default implementation of <see cref="IFido2NetLibBuilder"/> for configuring FIDO2 services.
206
+ /// </summary>
96
207
public class Fido2NetLibBuilder : IFido2NetLibBuilder
97
208
{
98
209
/// <summary>
0 commit comments