コード例 #1
0
        /// <summary>
        /// Registers the OpenIddict Quartz.NET integration 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 Quartz.NET services.</param>
        /// <remarks>This extension can be safely called multiple times.</remarks>
        /// <returns>The <see cref="OpenIddictCoreBuilder"/>.</returns>
        public static OpenIddictCoreBuilder UseQuartz(
            this OpenIddictCoreBuilder builder, Action <OpenIddictQuartzBuilder> configuration)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            configuration(builder.UseQuartz());

            return(builder);
        }
コード例 #2
0
        /// <summary>
        /// Registers the MongoDB stores services in the DI container and
        /// configures OpenIddict to use the MongoDB entities by default.
        /// </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 MongoDB services.</param>
        /// <remarks>This extension can be safely called multiple times.</remarks>
        /// <returns>The <see cref="OpenIddictCoreBuilder"/>.</returns>
        public static OpenIddictCoreBuilder UseMongoDb(
            this OpenIddictCoreBuilder builder, Action <OpenIddictMongoDbBuilder> configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            configuration(builder.UseMongoDb());

            return(builder);
        }
コード例 #3
0
        /// <summary>
        /// Registers the Entity Framework 6.x stores services in the DI container and
        /// configures OpenIddict to use the Entity Framework 6.x entities by default.
        /// </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 Entity Framework 6.x services.</param>
        /// <remarks>This extension can be safely called multiple times.</remarks>
        /// <returns>The <see cref="OpenIddictCoreBuilder"/>.</returns>
        public static OpenIddictCoreBuilder UseEntityFramework(
            this OpenIddictCoreBuilder builder, Action <OpenIddictEntityFrameworkBuilder> configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            configuration(builder.UseEntityFramework());

            return(builder);
        }
        public static OpenIddictCoreBuilder UseThreaxIdServerEf(this OpenIddictCoreBuilder builder, Action <Options> configure)
        {
            var options = new Options();

            configure.Invoke(options);

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

            // Since Entity Framework Core may be used with databases performing case-insensitive
            // or culture-sensitive comparisons, ensure the additional filtering logic is enforced
            // in case case-sensitive stores were registered before this extension was called.
            builder.Configure(options => options.DisableAdditionalFiltering = false);

            builder.SetDefaultApplicationEntity <Client>()
            .SetDefaultAuthorizationEntity <Authorization>()
            .SetDefaultScopeEntity <Scope>()
            .SetDefaultTokenEntity <Token>();

            builder.ReplaceApplicationStoreResolver <ApplicationStoreResolver>()
            .ReplaceAuthorizationStoreResolver <AuthorizationStoreResolver>()
            .ReplaceScopeStoreResolver <ScopeStoreResolver>()
            .ReplaceTokenStoreResolver <TokenStoreResolver>();

            builder.ReplaceApplicationManager(typeof(ThreaxOpenIddictApplicationManager <>));

            builder.Services.TryAddScoped <ApplicationStore>();
            builder.Services.TryAddScoped <AuthorizationStore>();
            builder.Services.TryAddScoped <ScopeStore>();
            builder.Services.TryAddScoped <TokenStore>();

            builder.Services.AddDbContext <ConfigurationDbContext>(o =>
            {
                options.SetupConfigurationDbContext.Invoke(o);
            });

            builder.Services.AddDbContext <OperationDbContext>(o =>
            {
                options.SetupOperationDbContext.Invoke(o);
            });

            return(builder);
        }
コード例 #5
0
        /// <summary>
        /// Registers the NHibernate stores services in the DI container and
        /// configures OpenIddict to use the NHibernate entities by default.
        /// </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 NHibernate services.</param>
        /// <remarks>This extension can be safely called multiple times.</remarks>
        /// <returns>The <see cref="OpenIddictCoreBuilder"/>.</returns>
        public static OpenIddictCoreBuilder UseNHibernate(
            [NotNull] this OpenIddictCoreBuilder builder,
            [NotNull] Action <OpenIddictNHibernateBuilder> configuration)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

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

            configuration(builder.UseNHibernate());

            return(builder);
        }
コード例 #6
0
        /// <summary>
        /// Registers the Entity Framework 6.x stores. Note: when using the Entity Framework stores,
        /// the application <see cref="DbContext"/> MUST be manually registered in the DI container and
        /// the entities MUST be derived from the models contained in the OpenIddict.Models package.
        /// </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="OpenIddictCoreBuilder"/>.</returns>
        public static OpenIddictCoreBuilder AddEntityFrameworkStores <TContext>([NotNull] this OpenIddictCoreBuilder builder)
            where TContext : DbContext
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.TryAddScoped(typeof(OpenIddictApplicationStore <, , , ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictAuthorizationStore <, , , ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictScopeStore <, ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictTokenStore <, , , ,>));

            return(builder.ReplaceApplicationStoreResolver <OpenIddictApplicationStoreResolver <TContext> >()
                   .ReplaceAuthorizationStoreResolver <OpenIddictAuthorizationStoreResolver <TContext> >()
                   .ReplaceScopeStoreResolver <OpenIddictScopeStoreResolver <TContext> >()
                   .ReplaceTokenStoreResolver <OpenIddictTokenStoreResolver <TContext> >());
        }
コード例 #7
0
        /// <summary>
        /// Registers the OpenIddict Quartz.NET integration 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="OpenIddictQuartzBuilder"/>.</returns>
        public static OpenIddictQuartzBuilder UseQuartz(this OpenIddictCoreBuilder builder)
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddQuartz();

            // The OpenIddict job is registered as a service to allow
            // Quartz.NET's DI integration to resolve it from the DI.
            builder.Services.TryAddTransient <OpenIddictQuartzJob>();

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

            return(new OpenIddictQuartzBuilder(builder.Services));
        }
コード例 #8
0
        public static OpenIddictCoreBuilder UseYesSql(this OpenIddictCoreBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            // Since the YesSql stores may be used with databases performing case-insensitive or
            // culture-sensitive comparisons, ensure the additional filtering logic is enforced
            // in case case-sensitive stores were registered before this extension was called.
            builder.Configure(options => options.DisableAdditionalFiltering = false);

            builder.SetDefaultApplicationEntity <OpenIdApplication>()
            .SetDefaultAuthorizationEntity <OpenIdAuthorization>()
            .SetDefaultScopeEntity <OpenIdScope>()
            .SetDefaultTokenEntity <OpenIdToken>();

            builder.ReplaceApplicationStoreResolver <OpenIdApplicationStoreResolver>()
            .ReplaceAuthorizationStoreResolver <OpenIdAuthorizationStoreResolver>()
            .ReplaceScopeStoreResolver <OpenIdScopeStoreResolver>()
            .ReplaceTokenStoreResolver <OpenIdTokenStoreResolver>();

            builder.Services.TryAddSingleton <OpenIdApplicationStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIdAuthorizationStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIdScopeStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIdTokenStoreResolver.TypeResolutionCache>();

            builder.Services.TryAddScoped(typeof(OpenIdApplicationStore <>));
            builder.Services.TryAddScoped(typeof(OpenIdAuthorizationStore <>));
            builder.Services.TryAddScoped(typeof(OpenIdScopeStore <>));
            builder.Services.TryAddScoped(typeof(OpenIdTokenStore <>));

            builder.Services.TryAddEnumerable(new[]
            {
                ServiceDescriptor.Singleton <IIndexProvider, OpenIdApplicationIndexProvider>(),
                ServiceDescriptor.Singleton <IIndexProvider, OpenIdAuthorizationIndexProvider>(),
                ServiceDescriptor.Singleton <IIndexProvider, OpenIdScopeIndexProvider>(),
                ServiceDescriptor.Singleton <IIndexProvider, OpenIdTokenIndexProvider>()
            });

            return(builder);
        }
コード例 #9
0
        public static OpenIddictCoreBuilder UseEpiManagers(this OpenIddictCoreBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.ReplaceApplicationManager(typeof(EpiOpenIdApplicationManager <>));
            builder.ReplaceScopeManager(typeof(EpiOpenIdScopeManager <>));
            builder.ReplaceAuthorizationManager(typeof(EpiOpenIdAuthorizationManager <>));
            builder.ReplaceTokenManager(typeof(EpiOpenIdTokenManager <>));

            builder.Services.TryAddScoped(provider => (IEpiOpenIdApplicationManager)
                                          provider.GetRequiredService <IOpenIddictApplicationManager>());
            builder.Services.TryAddScoped(provider => (IEpiOpenIdScopeManager)
                                          provider.GetRequiredService <IOpenIddictScopeManager>());
            builder.Services.TryAddScoped(provider => (IEpiOpenIdAuthorizationManager)
                                          provider.GetRequiredService <IOpenIddictAuthorizationManager>());
            builder.Services.TryAddScoped(provider => (IEpiOpenIdTokenManager)
                                          provider.GetRequiredService <IOpenIddictTokenManager>());

            return(builder);
        }
        /// <summary>
        /// Registers the Entity Framework Core stores services in the DI container and
        /// configures OpenIddict to use the Entity Framework Core entities by default.
        /// </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="OpenIddictEntityFrameworkCoreBuilder"/>.</returns>
        public static OpenIddictEntityFrameworkCoreBuilder UseEntityFrameworkCore([NotNull] this OpenIddictCoreBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.SetDefaultApplicationEntity <OpenIddictApplication>()
            .SetDefaultAuthorizationEntity <OpenIddictAuthorization>()
            .SetDefaultScopeEntity <OpenIddictScope>()
            .SetDefaultTokenEntity <OpenIddictToken>();

            builder.ReplaceApplicationStoreResolver <OpenIddictApplicationStoreResolver>()
            .ReplaceAuthorizationStoreResolver <OpenIddictAuthorizationStoreResolver>()
            .ReplaceScopeStoreResolver <OpenIddictScopeStoreResolver>()
            .ReplaceTokenStoreResolver <OpenIddictTokenStoreResolver>();

            builder.Services.TryAddScoped(typeof(OpenIddictApplicationStore <, , , ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictAuthorizationStore <, , , ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictScopeStore <, ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictTokenStore <, , , ,>));

            return(new OpenIddictEntityFrameworkCoreBuilder(builder.Services));
        }
コード例 #11
0
        /// <summary>
        /// Registers the MongoDB stores services in the DI container and
        /// configures OpenIddict to use the MongoDB entities by default.
        /// </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="OpenIddictMongoDbBuilder"/>.</returns>
        public static OpenIddictMongoDbBuilder UseMongoDb <TKey>(this OpenIddictCoreBuilder builder) where TKey : notnull
        {
            if (builder is null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            // Note: Mongo uses simple binary comparison checks by default so the additional
            // query filtering applied by the default OpenIddict managers can be safely disabled.
            builder.DisableAdditionalFiltering();

            builder.SetDefaultApplicationEntity <OpenIddictMongoDbApplication <TKey> >()
            .SetDefaultAuthorizationEntity <OpenIddictMongoDbAuthorization <TKey> >()
            .SetDefaultScopeEntity <OpenIddictMongoDbScope <TKey> >()
            .SetDefaultTokenEntity <OpenIddictMongoDbToken <TKey> >();

            // Note: the Mongo stores/resolvers don't depend on scoped/transient services and thus
            // can be safely registered as singleton services and shared/reused across requests.
            builder.ReplaceApplicationStoreResolver <OpenIddictMongoDbApplicationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceAuthorizationStoreResolver <OpenIddictMongoDbAuthorizationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceScopeStoreResolver <OpenIddictMongoDbScopeStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceTokenStoreResolver <OpenIddictMongoDbTokenStoreResolver>(ServiceLifetime.Singleton);

            builder.Services.TryAddSingleton(typeof(OpenIddictMongoDbApplicationStore <,>));
            builder.Services.TryAddSingleton(typeof(OpenIddictMongoDbAuthorizationStore <,>));
            builder.Services.TryAddSingleton(typeof(OpenIddictMongoDbScopeStore <,>));
            builder.Services.TryAddSingleton(typeof(OpenIddictMongoDbTokenStore <,>));

            builder.Services.TryAddSingleton(GuidKeyGenerator.Default);
            builder.Services.TryAddSingleton(ObjectIdKeyGenerator.Default);
            builder.Services.TryAddSingleton(StringKeyGenerator.Default);

            builder.Services.TryAddSingleton <IOpenIddictMongoDbContext, OpenIddictMongoDbContext>();

            return(new OpenIddictMongoDbBuilder(builder.Services));
        }
コード例 #12
0
        /// <summary>
        /// Registers the NHibernate stores services in the DI container and
        /// configures OpenIddict to use the NHibernate entities by default.
        /// </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="OpenIddictNHibernateBuilder"/>.</returns>
        public static OpenIddictNHibernateBuilder UseNHibernate([NotNull] this OpenIddictCoreBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            // Since NHibernate may be used with databases performing case-insensitive or
            // culture-sensitive comparisons, ensure the additional filtering logic is enforced
            // in case case-sensitive stores were registered before this extension was called.
            builder.Configure(options => options.DisableAdditionalFiltering = false);

            builder.SetDefaultApplicationEntity <OpenIddictApplication>()
            .SetDefaultAuthorizationEntity <OpenIddictAuthorization>()
            .SetDefaultScopeEntity <OpenIddictScope>()
            .SetDefaultTokenEntity <OpenIddictToken>();

            builder.ReplaceApplicationStoreResolver <OpenIddictApplicationStoreResolver>()
            .ReplaceAuthorizationStoreResolver <OpenIddictAuthorizationStoreResolver>()
            .ReplaceScopeStoreResolver <OpenIddictScopeStoreResolver>()
            .ReplaceTokenStoreResolver <OpenIddictTokenStoreResolver>();

            builder.Services.TryAddSingleton <OpenIddictApplicationStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIddictAuthorizationStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIddictScopeStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIddictTokenStoreResolver.TypeResolutionCache>();

            builder.Services.TryAddScoped(typeof(OpenIddictApplicationStore <, , ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictAuthorizationStore <, , ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictScopeStore <,>));
            builder.Services.TryAddScoped(typeof(OpenIddictTokenStore <, , ,>));

            builder.Services.TryAddScoped <IOpenIddictNHibernateContext, OpenIddictNHibernateContext>();

            return(new OpenIddictNHibernateBuilder(builder.Services));
        }