/// <summary> /// Registers the OpenIddict client 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="OpenIddictClientOwinBuilder"/>.</returns> public static OpenIddictClientOwinBuilder UseOwin(this OpenIddictClientBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddWebEncoders(); // Note: unlike regular OWIN middleware, the OpenIddict client 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 <OpenIddictClientOwinMiddleware>(); // Register the built-in event handlers used by the OpenIddict OWIN client components. // Note: the order used here is not important, as the actual order is set in the options. builder.Services.TryAdd(OpenIddictClientOwinHandlers.DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor)); // Register the built-in filters used by the default OpenIddict OWIN client event handlers. builder.Services.TryAddSingleton <RequireErrorPassthroughEnabled>(); builder.Services.TryAddSingleton <RequireOwinRequest>(); builder.Services.TryAddSingleton <RequireRedirectionEndpointPassthroughEnabled>(); // Register the option initializer used by the OpenIddict OWIN client integration services. // Note: TryAddEnumerable() is used here to ensure the initializers are only registered once. builder.Services.TryAddEnumerable(new[] { ServiceDescriptor.Singleton <IConfigureOptions <OpenIddictClientOptions>, OpenIddictClientOwinConfiguration>(), ServiceDescriptor.Singleton <IPostConfigureOptions <OpenIddictClientOwinOptions>, OpenIddictClientOwinConfiguration>() }); return(new OpenIddictClientOwinBuilder(builder.Services)); }
/// <summary> /// Registers the OpenIddict client 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="OpenIddictClientAspNetCoreBuilder"/>.</returns> public static OpenIddictClientAspNetCoreBuilder UseAspNetCore(this OpenIddictClientBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddAuthentication(); builder.Services.TryAddScoped <OpenIddictClientAspNetCoreHandler>(); // Register the built-in event handlers used by the OpenIddict ASP.NET Core client components. // Note: the order used here is not important, as the actual order is set in the options. builder.Services.TryAdd(OpenIddictClientAspNetCoreHandlers.DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor)); // Register the built-in filters used by the default OpenIddict ASP.NET Core client event handlers. builder.Services.TryAddSingleton <RequireErrorPassthroughEnabled>(); builder.Services.TryAddSingleton <RequireHttpRequest>(); builder.Services.TryAddSingleton <RequireRedirectionEndpointPassthroughEnabled>(); builder.Services.TryAddSingleton <RequireStatusCodePagesIntegrationEnabled>(); // Register the option initializer used by the OpenIddict ASP.NET Core client integration services. // Note: TryAddEnumerable() is used here to ensure the initializers are only registered once. builder.Services.TryAddEnumerable(new[] { ServiceDescriptor.Singleton <IConfigureOptions <AuthenticationOptions>, OpenIddictClientAspNetCoreConfiguration>(), ServiceDescriptor.Singleton <IPostConfigureOptions <AuthenticationOptions>, OpenIddictClientAspNetCoreConfiguration>(), ServiceDescriptor.Singleton <IConfigureOptions <OpenIddictClientOptions>, OpenIddictClientAspNetCoreConfiguration>() }); return(new OpenIddictClientAspNetCoreBuilder(builder.Services)); }
/// <summary> /// Registers the OpenIddict client/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="OpenIddictClientBuilder"/>.</returns> public static OpenIddictClientSystemNetHttpBuilder UseSystemNetHttp(this OpenIddictClientBuilder 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(OpenIddictClientSystemNetHttpHandlers.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 <OpenIddictClientOptions>, OpenIddictClientSystemNetHttpConfiguration>(), ServiceDescriptor.Singleton <IConfigureOptions <HttpClientFactoryOptions>, OpenIddictClientSystemNetHttpConfiguration>() }); return(new OpenIddictClientSystemNetHttpBuilder(builder.Services)); }
/// <summary> /// Registers the OpenIddict ASP.NET Core Data Protection client services in the DI container /// and configures OpenIddict to validate and issue ASP.NET Data Protection-based tokens. /// </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="OpenIddictClientBuilder"/>.</returns> public static OpenIddictClientDataProtectionBuilder UseDataProtection(this OpenIddictClientBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } builder.Services.AddDataProtection(); // Register the built-in server 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(OpenIddictClientDataProtectionHandlers.DefaultHandlers.Select(descriptor => descriptor.ServiceDescriptor)); // Register the built-in filters used by the default OpenIddict Data Protection event handlers. builder.Services.TryAddSingleton <RequireDataProtectionTokenFormat>(); // Note: TryAddEnumerable() is used here to ensure the initializers are registered only once. builder.Services.TryAddEnumerable(new[] { ServiceDescriptor.Singleton <IConfigureOptions <OpenIddictClientOptions>, OpenIddictClientDataProtectionConfiguration>(), ServiceDescriptor.Singleton <IPostConfigureOptions <OpenIddictClientDataProtectionOptions>, OpenIddictClientDataProtectionConfiguration>() }); return(new OpenIddictClientDataProtectionBuilder(builder.Services)); }
/// <summary> /// Registers the OpenIddict client Web integration 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="OpenIddictClientBuilder"/>.</returns> public static OpenIddictClientBuilder UseWebProviders( this OpenIddictClientBuilder builder, Action <OpenIddictClientWebIntegrationBuilder> configuration) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } configuration(builder.UseWebProviders()); return(builder); }
/// <summary> /// Registers the OpenIddict client services for ASP.NET Core 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 client services.</param> /// <remarks>This extension can be safely called multiple times.</remarks> /// <returns>The <see cref="OpenIddictClientBuilder"/>.</returns> public static OpenIddictClientBuilder UseAspNetCore( this OpenIddictClientBuilder builder, Action <OpenIddictClientAspNetCoreBuilder> configuration) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } if (configuration is null) { throw new ArgumentNullException(nameof(configuration)); } configuration(builder.UseAspNetCore()); return(builder); }
/// <summary> /// Registers the OpenIddict client Web 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="OpenIddictClientWebIntegrationBuilder"/>.</returns> public static OpenIddictClientWebIntegrationBuilder UseWebProviders(this OpenIddictClientBuilder builder) { if (builder is null) { throw new ArgumentNullException(nameof(builder)); } // Register the built-in event handlers used by the OpenIddict client Web components. // Note: the order used here is not important, as the actual order is set in the options. builder.Services.TryAdd(OpenIddictClientWebIntegrationHandlers.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 <OpenIddictClientOptions>, OpenIddictClientWebIntegrationConfiguration>() }); return(new OpenIddictClientWebIntegrationBuilder(builder.Services)); }