コード例 #1
0
        /// <summary>
        /// Configures the persisted grant context.
        /// </summary>
        /// <param name="modelBuilder">The model builder.</param>
        /// <param name="storeOptions">The store options.</param>
        public static void ConfigurePersistedGrantContext(
            this ModelBuilder modelBuilder,
            EntityFrameworkOptions storeOptions)
        {
            if (!string.IsNullOrWhiteSpace(storeOptions.DefaultSchema))
            {
                modelBuilder.HasDefaultSchema(storeOptions.DefaultSchema);
            }

            modelBuilder.Entity <PersistedGrant>(grant =>
            {
                grant.ToTable(storeOptions.PersistedGrants);

                grant.Property(x => x.Key)
                .HasMaxLength(200)
                .ValueGeneratedNever();

                grant.Property(x => x.Type)
                .HasMaxLength(50)
                .IsRequired();

                grant.Property(x => x.SubjectId)
                .HasMaxLength(200);

                grant.Property(x => x.ClientId)
                .HasMaxLength(200)
                .IsRequired();

                grant.Property(x => x.CreationTime)
                .IsRequired();

                // 50000 chosen to be explicit to allow enough size to avoid
                // truncation, yet stay beneath the MySql row size limit of
                // ~65K apparently anything over 4K converts to nvarchar(max)
                // on SqlServer
                grant.Property(x => x.Data)
                .HasMaxLength(50000)
                .IsRequired();

                grant.HasKey(x => x.Key);

                grant.HasIndex(x => new { x.SubjectId, x.ClientId, x.Type });
            });
        }
コード例 #2
0
 public ExampleDataStoreInitializer(
     EntityFrameworkOptions options,
     ApplicationOptions appOptions,
     ILogger <ConfigBasedStoreInitializer> logger,
     MigrationDbContext migrationDbContext,
     IConfigurationDbContext configurationDbContext,
     IPersistedGrantDbContext persistedGrantDbContext,
     IUserAccountDbContext userAccountDbContext,
     ICrypto crypto)
 {
     this.options                 = options;
     this.appOptions              = appOptions;
     this.logger                  = logger;
     this.migrationDbContext      = migrationDbContext;
     this.configurationDbContext  = configurationDbContext;
     this.persistedGrantDbContext = persistedGrantDbContext;
     this.userAccountDbContext    = userAccountDbContext;
     this.crypto                  = crypto;
 }
コード例 #3
0
        public TokenCleanupService(
            IServiceProvider serviceProvider,
            ILogger <TokenCleanupService> logger,
            EntityFrameworkOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (options.TokenCleanupInterval < 1)
            {
                throw new ArgumentException(
                          "interval must be more than 1 second");
            }

            this._logger = logger ?? throw
                               new ArgumentNullException(nameof(logger));

            this._serviceProvider = serviceProvider ?? throw
                                        new ArgumentNullException(nameof(serviceProvider));

            this._interval = TimeSpan.FromSeconds(options.TokenCleanupInterval);
        }
コード例 #4
0
 public VoucherDbContext(IOptionsSnapshot <EntityFrameworkOptions> options)
 {
     Options = options.Value;
 }
コード例 #5
0
 public EntityFrameworkEntitiesModule(KunoStack stack, EntityFrameworkOptions options)
 {
     _stack   = stack;
     _options = options;
 }
コード例 #6
0
        /// <summary>
        /// Configures the user account context.
        /// </summary>
        /// <param name="modelBuilder">The model builder.</param>
        /// <param name="storeOptions">The store options.</param>
        public static void ConfigureUserAccountContext(
            this ModelBuilder modelBuilder,
            EntityFrameworkOptions storeOptions)
        {
            if (!string.IsNullOrWhiteSpace(storeOptions.DefaultSchema))
            {
                modelBuilder.HasDefaultSchema(storeOptions.DefaultSchema);
            }

            modelBuilder.Entity <UserAccount>(userAccount =>
            {
                userAccount
                .ToTable(storeOptions.UserAccount);

                userAccount.HasKey(x => new { x.Id });

                userAccount.Property(x => x.Email)
                .HasMaxLength(254)
                .IsRequired();

                userAccount.Property(x => x.IsEmailVerified)
                .IsRequired();

                userAccount.Property(x => x.EmailVerifiedAt);

                userAccount.Property(x => x.IsLoginAllowed)
                .IsRequired();

                userAccount.Property(x => x.LastLoginAt);

                userAccount.Property(x => x.FailedLoginCount);

                userAccount.Property(x => x.PasswordHash)
                .HasMaxLength(200);

                userAccount.Property(x => x.PasswordChangedAt);

                userAccount.Property(x => x.VerificationKey)
                .HasMaxLength(100);

                userAccount.Property(x => x.VerificationPurpose);

                userAccount.Property(x => x.VerificationKeySentAt);

                userAccount.Property(x => x.VerificationStorage)
                .HasMaxLength(2000);

                userAccount.Property(x => x.CreatedAt);

                userAccount.Property(x => x.UpdatedAt);

                userAccount.Property(x => x.CreatedBy);

                userAccount.Property(x => x.CreationKind);

                userAccount.HasMany(x => x.Accounts)
                .WithOne(x => x.UserAccount)
                .HasForeignKey(x => x.UserAccountId)
                .IsRequired().OnDelete(DeleteBehavior.Cascade);

                userAccount.HasMany(x => x.Claims)
                .WithOne(x => x.UserAccount)
                .HasForeignKey(x => x.UserAccountId)
                .IsRequired().OnDelete(DeleteBehavior.Cascade);

                userAccount
                .HasIndex(x => x.Email)
                .IsUnique();
            });

            modelBuilder.Entity <ExternalAccount>(externalAccount =>
            {
                externalAccount
                .ToTable(storeOptions.ExternalAccount);

                externalAccount.HasKey(x => new
                {
                    x.UserAccountId,
                    x.Provider,
                    x.Subject
                });

                externalAccount.Property(x => x.Provider)
                .IsRequired();

                externalAccount.Property(x => x.Subject)
                .IsRequired();

                externalAccount.Property(x => x.Email)
                .IsRequired().HasMaxLength(254);

                externalAccount.Property(x => x.IsLoginAllowed);

                externalAccount.Property(x => x.LastLoginAt);

                externalAccount.Property(x => x.CreatedAt)
                .IsRequired();

                externalAccount.Property(x => x.UpdatedAt)
                .IsRequired();

                externalAccount.Property(x => x.LastLoginAt);
            });

            modelBuilder.Entity <UserAccountClaim>(claim =>
            {
                claim
                .ToTable(storeOptions.UserAccountClaim);

                claim.HasKey(x => new { x.Id });

                claim.Property(x => x.Type)
                .HasMaxLength(250).IsRequired();

                claim.Property(x => x.Value)
                .HasMaxLength(250).IsRequired();

                claim.Property(x => x.ValueType)
                .HasMaxLength(2000);
            });
        }
コード例 #7
0
        /// <summary>
        /// Configures the client context.
        /// </summary>
        /// <param name="modelBuilder">The model builder.</param>
        /// <param name="storeOptions">The store options.</param>
        public static void ConfigureClientContext(
            this ModelBuilder modelBuilder,
            EntityFrameworkOptions storeOptions)
        {
            if (!string.IsNullOrWhiteSpace(storeOptions.DefaultSchema))
            {
                modelBuilder.HasDefaultSchema(storeOptions.DefaultSchema);
            }

            modelBuilder.Entity <Client>(client =>
            {
                client.ToTable(storeOptions.Client);
                client.HasKey(x => x.Id);

                client.Property(x => x.ClientId)
                .HasMaxLength(200)
                .IsRequired();

                client.Property(x => x.ProtocolType)
                .HasMaxLength(200)
                .IsRequired();

                client.Property(x => x.ClientName)
                .HasMaxLength(200);

                client.Property(x => x.ClientUri)
                .HasMaxLength(2000);

                client.Property(x => x.LogoUri)
                .HasMaxLength(2000);

                client.Property(x => x.Description)
                .HasMaxLength(1000);

                client.Property(x => x.FrontChannelLogoutUri)
                .HasMaxLength(2000);

                client.Property(x => x.BackChannelLogoutUri)
                .HasMaxLength(2000);

                client.Property(x => x.ClientClaimsPrefix)
                .HasMaxLength(200);

                client.Property(x => x.PairWiseSubjectSalt)
                .HasMaxLength(200);

                client.HasIndex(x => x.ClientId).IsUnique();

                client.HasMany(x => x.AllowedGrantTypes)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                client.HasMany(x => x.RedirectUris)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                client.HasMany(x => x.PostLogoutRedirectUris)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                client.HasMany(x => x.AllowedScopes)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                client.HasMany(x => x.ClientSecrets)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                client.HasMany(x => x.Claims)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                client.HasMany(x => x.IdentityProviderRestrictions)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                client.HasMany(x => x.AllowedCorsOrigins)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                client.HasMany(x => x.Properties)
                .WithOne(x => x.Client)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);
            });

            modelBuilder.Entity <ClientGrantType>(grantType =>
            {
                grantType.ToTable(storeOptions.ClientGrantType);
                grantType.Property(x => x.GrantType)
                .HasMaxLength(250)
                .IsRequired();
            });

            modelBuilder.Entity <ClientRedirectUri>(redirectUri =>
            {
                redirectUri.ToTable(storeOptions.ClientRedirectUri);
                redirectUri.Property(x => x.RedirectUri)
                .HasMaxLength(2000)
                .IsRequired();
            });

            modelBuilder
            .Entity <ClientPostLogoutRedirectUri>(postLogoutRedirectUri =>
            {
                postLogoutRedirectUri
                .ToTable(storeOptions.ClientPostLogoutRedirectUri);

                postLogoutRedirectUri
                .Property(x => x.PostLogoutRedirectUri)
                .HasMaxLength(2000)
                .IsRequired();
            });

            modelBuilder.Entity <ClientScope>(scope =>
            {
                scope.ToTable(storeOptions.ClientScopes);

                scope.Property(x => x.Scope)
                .HasMaxLength(200)
                .IsRequired();
            });

            modelBuilder.Entity <ClientSecret>(secret =>
            {
                secret.ToTable(storeOptions.ClientSecret);

                secret.Property(x => x.Value)
                .HasMaxLength(2000).IsRequired();

                secret.Property(x => x.Type)
                .HasMaxLength(250);

                secret.Property(x => x.Description)
                .HasMaxLength(2000);
            });

            modelBuilder.Entity <ClientClaim>(claim =>
            {
                claim.ToTable(storeOptions.ClientClaim);

                claim.Property(x => x.Type)
                .HasMaxLength(250).IsRequired();

                claim.Property(x => x.Value)
                .HasMaxLength(250).IsRequired();
            });

            modelBuilder.Entity <ClientIdPRestriction>(idPRestriction =>
            {
                idPRestriction.ToTable(storeOptions.ClientIdPRestriction);

                idPRestriction.Property(x => x.Provider)
                .HasMaxLength(200)
                .IsRequired();
            });

            modelBuilder.Entity <ClientCorsOrigin>(corsOrigin =>
            {
                corsOrigin.ToTable(storeOptions.ClientCorsOrigin);
                corsOrigin.Property(x => x.Origin)
                .HasMaxLength(150)
                .IsRequired();
            });

            modelBuilder.Entity <ClientProperty>(property =>
            {
                property.ToTable(storeOptions.ClientProperty);

                property.Property(x => x.Key)
                .HasMaxLength(250).IsRequired();

                property.Property(x => x.Value)
                .HasMaxLength(2000).IsRequired();
            });
        }
コード例 #8
0
        /// <summary>
        /// Configures the resources context.
        /// </summary>
        /// <param name="modelBuilder">The model builder.</param>
        /// <param name="storeOptions">The store options.</param>
        public static void ConfigureResourcesContext(
            this ModelBuilder modelBuilder,
            EntityFrameworkOptions storeOptions)
        {
            if (!string.IsNullOrWhiteSpace(storeOptions.DefaultSchema))
            {
                modelBuilder.HasDefaultSchema(storeOptions.DefaultSchema);
            }

            modelBuilder.Entity <IdentityResource>(identityResource =>
            {
                identityResource
                .ToTable(storeOptions.IdentityResource)
                .HasKey(x => x.Id);

                identityResource.Property(x => x.Name)
                .HasMaxLength(200)
                .IsRequired();

                identityResource.Property(x => x.DisplayName)
                .HasMaxLength(200);

                identityResource.Property(x => x.Description)
                .HasMaxLength(1000);

                identityResource.HasIndex(x => x.Name)
                .IsUnique();

                identityResource.HasMany(x => x.UserClaims)
                .WithOne(x => x.IdentityResource)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);
            });

            modelBuilder.Entity <IdentityClaim>(claim =>
            {
                claim
                .ToTable(storeOptions.IdentityClaim)
                .HasKey(x => x.Id);

                claim.Property(x => x.Type)
                .HasMaxLength(200)
                .IsRequired();
            });

            modelBuilder.Entity <ApiResource>(apiResource =>
            {
                apiResource
                .ToTable(storeOptions.ApiResource)
                .HasKey(x => x.Id);

                apiResource.Property(x => x.Name)
                .HasMaxLength(200)
                .IsRequired();

                apiResource.Property(x => x.DisplayName)
                .HasMaxLength(200);

                apiResource.Property(x => x.Description)
                .HasMaxLength(1000);

                apiResource.HasIndex(x => x.Name).IsUnique();

                apiResource.HasMany(x => x.Secrets)
                .WithOne(x => x.ApiResource)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                apiResource.HasMany(x => x.Scopes)
                .WithOne(x => x.ApiResource)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);

                apiResource.HasMany(x => x.UserClaims)
                .WithOne(x => x.ApiResource)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);
            });

            modelBuilder.Entity <ApiSecret>(apiSecret =>
            {
                apiSecret
                .ToTable(storeOptions.ApiSecret)
                .HasKey(x => x.Id);

                apiSecret.Property(x => x.Description)
                .HasMaxLength(1000);

                apiSecret.Property(x => x.Value)
                .HasMaxLength(2000);

                apiSecret.Property(x => x.Type)
                .HasMaxLength(250);
            });

            modelBuilder.Entity <ApiResourceClaim>(apiClaim =>
            {
                apiClaim
                .ToTable(storeOptions.ApiClaim)
                .HasKey(x => x.Id);

                apiClaim.Property(x => x.Type)
                .HasMaxLength(200)
                .IsRequired();
            });

            modelBuilder.Entity <ApiScope>(apiScope =>
            {
                apiScope
                .ToTable(storeOptions.ApiScope)
                .HasKey(x => x.Id);

                apiScope.Property(x => x.Name)
                .HasMaxLength(200)
                .IsRequired();

                apiScope.Property(x => x.DisplayName)
                .HasMaxLength(200);

                apiScope.Property(x => x.Description)
                .HasMaxLength(1000);

                apiScope.HasIndex(x => x.Name)
                .IsUnique();

                apiScope.HasMany(x => x.UserClaims)
                .WithOne(x => x.ApiScope)
                .IsRequired()
                .OnDelete(DeleteBehavior.Cascade);
            });

            modelBuilder.Entity <ApiScopeClaim>(apiScopeClaim =>
            {
                apiScopeClaim
                .ToTable(storeOptions.ApiScopeClaim)
                .HasKey(x => x.Id);

                apiScopeClaim.Property(x => x.Type)
                .HasMaxLength(200)
                .IsRequired();
            });
        }
コード例 #9
0
 public PersistedGrantDbContext(DbContextOptions <PersistedGrantDbContext> options, EntityFrameworkOptions storeOptions)
     : base(options)
 {
     if (storeOptions == null)
     {
         throw new ArgumentNullException(nameof(storeOptions));
     }
     _storeOptions = storeOptions;
 }
 internal static void AddUserAccountStore(this IServiceCollection services, EntityFrameworkOptions options)
 {
     services.AddDbContext <UserAccountDbContext>(options.DbContextOptions);
     services.AddScoped <IUserAccountDbContext, UserAccountDbContext>();
     services.AddTransient <IUserAccountStore, UserAccountStore>();
 }
 public static void AddDefaultStoreInitializer(this IServiceCollection services, EntityFrameworkOptions options)
 {
     services.AddDbContext <DefaultDbContext>(options.DbContextOptions);
     services.AddScoped <ConfigurationDbContext>();
     services.AddTransient <IStoreInitializer, DefaultStoreInitializer>();
 }
        public static void AddEntityFrameworkStores(this IServiceCollection services, EntityFrameworkOptions options)
        {
            services.AddConfigurationStore(options);
            services.AddOperationalStore(options);
            services.AddUserAccountStore(options);

            services.AddSingleton(options);
        }
コード例 #13
0
 public SubscriptionDbContext(IOptionsSnapshot <EntityFrameworkOptions> options)
 {
     Options = options.Value;
 }
コード例 #14
0
 public ConfigurationDbContext(DbContextOptions <ConfigurationDbContext> options, EntityFrameworkOptions storeOptions)
     : base(options)
 {
     this.storeOptions = storeOptions ?? throw new ArgumentNullException(nameof(storeOptions));
 }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SearchContext" /> class.
        /// </summary>
        /// <param name="options">The options.</param>
        public SearchContext(EntityFrameworkOptions options) : base(options.Search.ConnectionString)
        {
            Argument.NotNull(options, nameof(options));

            _options = options;
        }
コード例 #16
0
 public UserAccountDbContext(DbContextOptions <UserAccountDbContext> dbContextOptions, EntityFrameworkOptions options)
     : base(dbContextOptions)
 {
     if (options == null)
     {
         throw new ArgumentNullException(nameof(_options));
     }
     _options = options;
 }
 public OptionsPatternController(IOptions <EntityFrameworkOptions> entityFrameworkOptions, IOptions <ConnectionStringsOptions> connectionStringsOptions)
 {
     _entityFrameworkOptions   = entityFrameworkOptions.Value;
     _connectionStringsOptions = connectionStringsOptions.Value;
 }