/* * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) * See https://github.com/openiddict/openiddict-core for more information concerning * the license and the contributors participating to this project. */ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Http; using Microsoft.Extensions.Options; using OpenIddict.Validation; using OpenIddict.Validation.SystemNetHttp; namespace Microsoft.Extensions.DependencyInjection; /// /// Exposes extensions allowing to register the OpenIddict validation/System.Net.Http integration services. /// public static class OpenIddictValidationSystemNetHttpExtensions { /// /// Registers the OpenIddict validation/System.Net.Http integration services in the DI container. /// /// The services builder used by OpenIddict to register new services. /// This extension can be safely called multiple times. /// The instance. public static OpenIddictValidationSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictValidationBuilder builder) { ArgumentNullException.ThrowIfNull(builder); builder.Services.AddHttpClient(); // Register the built-in validation event handlers used by the OpenIddict System.Net.Http components. // Note: the order used here is not important, as the actual order is set in the options. builder.Services.TryAdd(OpenIddictValidationSystemNetHttpHandlers.DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor)); // Register the built-in filters used by the default OpenIddict System.Net.Http event handlers. builder.Services.TryAddSingleton(); // Note: TryAddEnumerable() is used here to ensure the initializers are registered only once. builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton< IConfigureOptions, OpenIddictValidationSystemNetHttpConfiguration>()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton< IConfigureOptions, OpenIddictValidationSystemNetHttpConfiguration>()); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton< IPostConfigureOptions, OpenIddictValidationSystemNetHttpConfiguration>()); return new OpenIddictValidationSystemNetHttpBuilder(builder.Services); } /// /// Registers the OpenIddict validation/System.Net.Http integration services in the DI container. /// /// The services builder used by OpenIddict to register new services. /// The configuration delegate used to configure the validation services. /// This extension can be safely called multiple times. /// The instance. public static OpenIddictValidationBuilder UseSystemNetHttp( this OpenIddictValidationBuilder builder, Action configuration) { ArgumentNullException.ThrowIfNull(builder); ArgumentNullException.ThrowIfNull(configuration); configuration(builder.UseSystemNetHttp()); return builder; } }