Exemple #1
0
        /// <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 == 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));
        }
Exemple #3
0
        /// <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([NotNull] this OpenIddictValidationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddWebEncoders();

            // 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));
        }
Exemple #4
0
        /// <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="OpenIddictValidationBuilder"/>.</returns>
        public static OpenIddictValidationServerIntegrationBuilder UseLocalServer([NotNull] this OpenIddictValidationBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            // Note: TryAddEnumerable() is used here to ensure the initializer is registered only once.
            builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <
                                                  IConfigureOptions <OpenIddictValidationOptions>, OpenIddictValidationServerIntegrationConfiguration>());

            return(new OpenIddictValidationServerIntegrationBuilder(builder.Services));
        }
Exemple #5
0
        /// <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>
        /// <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="OpenIddictBuilder"/>.</returns>
        public static OpenIddictValidationBuilder UseSystemNetHttp(
            this OpenIddictValidationBuilder builder, Action <OpenIddictValidationSystemNetHttpBuilder> configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            configuration(builder.UseSystemNetHttp());

            return(builder);
        }
        /// <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>
        /// <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 UseAspNetCore(
            this OpenIddictValidationBuilder builder, Action <OpenIddictValidationAspNetCoreBuilder> configuration)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configuration is null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            configuration(builder.UseAspNetCore());

            return(builder);
        }
Exemple #7
0
        /// <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="OpenIddictBuilder"/>.</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);
        }
Exemple #8
0
        /// <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>
        /// <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 UseOwin(
            [NotNull] this OpenIddictValidationBuilder builder,
            [NotNull] Action <OpenIddictValidationOwinBuilder> configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            configuration(builder.UseOwin());

            return(builder);
        }
Exemple #9
0
        /// <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 == 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(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));
        }