/// <summary> /// Registers the OpenIddict validation services for OWIN in the DI container. /// </summary> /// <param name="builder">The services builder used by OpenIddict to register new services.</param> /// <remarks>This extension can be safely called multiple times.</remarks> /// <returns>The <see cref="OpenIddictValidationOwinBuilder"/>.</returns> public static OpenIddictValidationOwinBuilder UseOwin(this OpenIddictValidationBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } // Note: unlike regular OWIN middleware, the OpenIddict validation middleware is registered // as a scoped service in the DI container. This allows containers that support middleware // resolution (like Autofac) to use it without requiring additional configuration. builder.Services.TryAddScoped <OpenIddictValidationOwinMiddleware>(); // Register the built-in event handlers used by the OpenIddict OWIN validation components. // Note: the order used here is not important, as the actual order is set in the options. builder.Services.TryAdd(DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor)); // Register the built-in filters used by the default OpenIddict OWIN validation event handlers. builder.Services.TryAddSingleton <RequireOwinRequest>(); // Register the option initializers used by the OpenIddict OWIN validation integration services. // Note: TryAddEnumerable() is used here to ensure the initializers are only registered once. builder.Services.TryAddEnumerable(new[] { ServiceDescriptor.Singleton <IConfigureOptions <OpenIddictValidationOptions>, OpenIddictValidationOwinConfiguration>() }); return(new OpenIddictValidationOwinBuilder(builder.Services)); }
/// <summary> /// Registers the OpenIddict validation/System.Net.Http integration services in the DI container. /// </summary> /// <param name="builder">The services builder used by OpenIddict to register new services.</param> /// <remarks>This extension can be safely called multiple times.</remarks> /// <returns>The <see cref="OpenIddictValidationBuilder"/>.</returns> public static OpenIddictValidationSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictValidationBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(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(DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor)); // Register the built-in filters used by the default OpenIddict System.Net.Http event handlers. builder.Services.TryAddSingleton <RequireHttpMetadataAddress>(); // Note: TryAddEnumerable() is used here to ensure the initializers are registered only once. builder.Services.TryAddEnumerable(new[] { ServiceDescriptor.Singleton <IConfigureOptions <OpenIddictValidationOptions>, OpenIddictValidationSystemNetHttpConfiguration>(), ServiceDescriptor.Singleton <IConfigureOptions <HttpClientFactoryOptions>, OpenIddictValidationSystemNetHttpConfiguration>() }); return(new OpenIddictValidationSystemNetHttpBuilder(builder.Services)); }
/// <summary> /// Registers the OpenIddict validation services for ASP.NET Core in the DI container. /// </summary> /// <param name="builder">The services builder used by OpenIddict to register new services.</param> /// <remarks>This extension can be safely called multiple times.</remarks> /// <returns>The <see cref="OpenIddictValidationAspNetCoreBuilder"/>.</returns> public static OpenIddictValidationAspNetCoreBuilder UseAspNetCore(this OpenIddictValidationBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddAuthentication(); builder.Services.TryAddScoped <OpenIddictValidationAspNetCoreHandler>(); // Register the built-in event handlers used by the OpenIddict ASP.NET Core validation components. // Note: the order used here is not important, as the actual order is set in the options. builder.Services.TryAdd(DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor)); // Register the built-in filters used by the default OpenIddict ASP.NET Core validation event handlers. builder.Services.TryAddSingleton <RequireHttpRequest>(); // Register the option initializer used by the OpenIddict ASP.NET Core validation integration services. // Note: TryAddEnumerable() is used here to ensure the initializers are only registered once. builder.Services.TryAddEnumerable(new[] { ServiceDescriptor.Singleton <IConfigureOptions <AuthenticationOptions>, OpenIddictValidationAspNetCoreConfiguration>(), ServiceDescriptor.Singleton <IPostConfigureOptions <AuthenticationOptions>, OpenIddictValidationAspNetCoreConfiguration>(), ServiceDescriptor.Singleton <IConfigureOptions <OpenIddictValidationOptions>, OpenIddictValidationAspNetCoreConfiguration>() }); return(new OpenIddictValidationAspNetCoreBuilder(builder.Services)); }
/// <summary> /// Registers the OpenIddict validation/server integration services in the DI container /// and automatically imports the configuration from the local OpenIddict server. /// </summary> /// <param name="builder">The services builder used by OpenIddict to register new services.</param> /// <remarks>This extension can be safely called multiple times.</remarks> /// <returns>The <see cref="OpenIddictValidationServerIntegrationBuilder"/>.</returns> public static OpenIddictValidationServerIntegrationBuilder UseLocalServer(this OpenIddictValidationBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } // Note: TryAddEnumerable() is used here to ensure the initializers are registered only once. builder.Services.TryAddEnumerable(new[] { ServiceDescriptor.Singleton <IConfigureOptions <OpenIddictValidationOptions>, OpenIddictValidationServerIntegrationConfiguration>(), ServiceDescriptor.Singleton <IPostConfigureOptions <OpenIddictValidationOptions>, OpenIddictValidationServerIntegrationConfiguration>() }); return(new OpenIddictValidationServerIntegrationBuilder(builder.Services)); }
/// <summary> /// Registers the OpenIddict validation/server integration services in the DI container /// and automatically imports the configuration from the local OpenIddict server. /// </summary> /// <param name="builder">The services builder used by OpenIddict to register new services.</param> /// <param name="configuration">The configuration delegate used to configure the validation services.</param> /// <remarks>This extension can be safely called multiple times.</remarks> /// <returns>The <see cref="OpenIddictValidationBuilder"/>.</returns> public static OpenIddictValidationBuilder UseLocalServer( this OpenIddictValidationBuilder builder, Action <OpenIddictValidationServerIntegrationBuilder> configuration) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } configuration(builder.UseLocalServer()); return(builder); }
/// <summary> /// Registers the OpenIddict ASP.NET Core Data Protection validation services in the DI container. /// </summary> /// <param name="builder">The services builder used by OpenIddict to register new services.</param> /// <param name="configuration">The configuration delegate used to configure the validation services.</param> /// <remarks>This extension can be safely called multiple times.</remarks> /// <returns>The <see cref="OpenIddictValidationBuilder"/>.</returns> public static OpenIddictValidationBuilder UseDataProtection( this OpenIddictValidationBuilder builder, Action <OpenIddictValidationDataProtectionBuilder> configuration) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } configuration(builder.UseDataProtection()); return(builder); }
/// <summary> /// Registers the OpenIddict ASP.NET Core Data Protection validation services in the DI container. /// </summary> /// <param name="builder">The services builder used by OpenIddict to register new services.</param> /// <remarks>This extension can be safely called multiple times.</remarks> /// <returns>The <see cref="OpenIddictValidationBuilder"/>.</returns> public static OpenIddictValidationDataProtectionBuilder UseDataProtection(this OpenIddictValidationBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddDataProtection(); // Register the built-in validation event handlers used by the OpenIddict Data Protection components. // Note: the order used here is not important, as the actual order is set in the options. builder.Services.TryAdd(OpenIddictValidationDataProtectionHandlers.DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor)); // Note: TryAddEnumerable() is used here to ensure the initializers are registered only once. builder.Services.TryAddEnumerable(new[] { ServiceDescriptor.Singleton <IConfigureOptions <OpenIddictValidationOptions>, OpenIddictValidationDataProtectionConfiguration>(), ServiceDescriptor.Singleton <IPostConfigureOptions <OpenIddictValidationDataProtectionOptions>, OpenIddictValidationDataProtectionConfiguration>() }); return(new OpenIddictValidationDataProtectionBuilder(builder.Services)); }