/// <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(this OpenIddictCoreBuilder builder)
        {
            if (builder == 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 <OpenIddictEntityFrameworkCoreApplication>()
            .SetDefaultAuthorizationEntity <OpenIddictEntityFrameworkCoreAuthorization>()
            .SetDefaultScopeEntity <OpenIddictEntityFrameworkCoreScope>()
            .SetDefaultTokenEntity <OpenIddictEntityFrameworkCoreToken>();

            builder.ReplaceApplicationStoreResolver <OpenIddictEntityFrameworkCoreApplicationStoreResolver>()
            .ReplaceAuthorizationStoreResolver <OpenIddictEntityFrameworkCoreAuthorizationStoreResolver>()
            .ReplaceScopeStoreResolver <OpenIddictEntityFrameworkCoreScopeStoreResolver>()
            .ReplaceTokenStoreResolver <OpenIddictEntityFrameworkCoreTokenStoreResolver>();

            builder.Services.TryAddSingleton <OpenIddictEntityFrameworkCoreApplicationStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIddictEntityFrameworkCoreAuthorizationStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIddictEntityFrameworkCoreScopeStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <OpenIddictEntityFrameworkCoreTokenStoreResolver.TypeResolutionCache>();

            builder.Services.TryAddScoped(typeof(OpenIddictEntityFrameworkCoreApplicationStore <, , , ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictEntityFrameworkCoreAuthorizationStore <, , , ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictEntityFrameworkCoreScopeStore <, ,>));
            builder.Services.TryAddScoped(typeof(OpenIddictEntityFrameworkCoreTokenStore <, , , ,>));

            return(new OpenIddictEntityFrameworkCoreBuilder(builder.Services));
        }
Ejemplo n.º 2
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>
        /// <remarks>This extension can be safely called multiple times.</remarks>
        /// <returns>The <see cref="OpenIddictEntityFrameworkBuilder"/>.</returns>
        public static OpenIddictEntityFrameworkBuilder UseEntityFramework([NotNull] this OpenIddictCoreBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddMemoryCache();

            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 OpenIddictEntityFrameworkBuilder(builder.Services));
        }
Ejemplo n.º 3
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([NotNull] this OpenIddictCoreBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddMemoryCache();

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

            // 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 <OpenIddictApplicationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceAuthorizationStoreResolver <OpenIddictAuthorizationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceScopeStoreResolver <OpenIddictScopeStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceTokenStoreResolver <OpenIddictTokenStoreResolver>(ServiceLifetime.Singleton);

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

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

            return(new OpenIddictMongoDbBuilder(builder.Services));
        }
Ejemplo n.º 4
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(this OpenIddictCoreBuilder builder)
        {
            if (builder == 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>()
            .SetDefaultAuthorizationEntity <OpenIddictMongoDbAuthorization>()
            .SetDefaultScopeEntity <OpenIddictMongoDbScope>()
            .SetDefaultTokenEntity <OpenIddictMongoDbToken>();

            // 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 <IOpenIddictMongoDbContext, OpenIddictMongoDbContext>();

            return(new OpenIddictMongoDbBuilder(builder.Services));
        }
        /// <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="CouchDbOpenIddictBuilder"/>.</returns>
        public static CouchDbOpenIddictBuilder UseCouchDb(this OpenIddictCoreBuilder builder)
        {
            Check.NotNull(builder, 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 <CouchDbOpenIddictApplication>()
            .SetDefaultAuthorizationEntity <CouchDbOpenIddictAuthorization>()
            .SetDefaultScopeEntity <CouchDbOpenIddictScope>()
            .SetDefaultTokenEntity <CouchDbOpenIddictToken>();

            // 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 <CouchDOpenIddictbApplicationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceAuthorizationStoreResolver <CouchDOpenIddictbAuthorizationStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceScopeStoreResolver <CouchDbOpenIddictScopeStoreResolver>(ServiceLifetime.Singleton)
            .ReplaceTokenStoreResolver <CouchDbOpenIddictTokenStoreResolver>(ServiceLifetime.Singleton);

            builder.Services.TryAddSingleton(typeof(CouchDbOpenIddictApplicationStore <>));
            builder.Services.TryAddSingleton(typeof(CouchDbOpenIddictAuthorizationStore <>));
            builder.Services.TryAddSingleton(typeof(CouchDbOpenIddictScopeStore <>));
            builder.Services.TryAddSingleton(typeof(CouchDbOpenIddictTokenStore <>));

            return(new CouchDbOpenIddictBuilder(builder.Services));
        }
Ejemplo n.º 6
0
        public static OpenIddictCoreBuilder UseEpiInmemoryStore(this OpenIddictCoreBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Configure(options => options.DisableAdditionalFiltering = false);

            builder.SetDefaultApplicationEntity <EpiOpenIdApplication>();
            builder.SetDefaultScopeEntity <EpiOpenIdScope>();
            builder.SetDefaultAuthorizationEntity <EpiOpenIdAuthorization>();
            builder.SetDefaultTokenEntity <EpiOpenIdToken>();

            builder.ReplaceApplicationStoreResolver <EpiOpenIdApplicationStoreResolver>();
            builder.ReplaceScopeStoreResolver <EpiOpenIdScopeStoreResolver>();
            builder.ReplaceAuthorizationStoreResolver <EpiOpenIdAuthorizationStoreResolver>();
            builder.ReplaceTokenStoreResolver <EpiOpenIdTokenStoreResolver>();

            builder.Services.TryAddSingleton <EpiOpenIdApplicationStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <EpiOpenIdScopeStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <EpiOpenIdAuthorizationStoreResolver.TypeResolutionCache>();
            builder.Services.TryAddSingleton <EpiOpenIdTokenStoreResolver.TypeResolutionCache>();

            builder.Services.TryAddScoped(typeof(EpiOpenIdApplicationStore <>));
            builder.Services.TryAddScoped(typeof(EpiOpenIdScopeStore <>));
            builder.Services.TryAddScoped(typeof(EpiOpenIdAuthorizationStore <>));
            builder.Services.TryAddScoped(typeof(EpiOpenIdTokenStore <>));

            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);
        }
Ejemplo n.º 8
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> >());
        }
Ejemplo n.º 9
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);
        }