|
1 |
| -// Copyright (c) .NET Foundation. All rights reserved. |
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
2 | 2 | // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
3 | 3 |
|
| 4 | +using System; |
4 | 5 | using System.Threading.Tasks;
|
5 | 6 | using IdentityServer4.EntityFramework.Entities;
|
6 | 7 | using IdentityServer4.EntityFramework.Extensions;
|
@@ -49,9 +50,47 @@ public ApiAuthorizationDbContext(
|
49 | 50 | /// <inheritdoc />
|
50 | 51 | protected override void OnModelCreating(ModelBuilder builder)
|
51 | 52 | {
|
52 |
| - |
53 | 53 | base.OnModelCreating(builder);
|
54 |
| - builder.ConfigurePersistedGrantContext(_operationalStoreOptions.Value); |
| 54 | + ConfigureGrantContext(builder, _operationalStoreOptions.Value); |
55 | 55 | }
|
| 56 | + |
| 57 | + private void ConfigureGrantContext(ModelBuilder modelBuilder, OperationalStoreOptions storeOptions) |
| 58 | + { |
| 59 | + if (!string.IsNullOrWhiteSpace(storeOptions.DefaultSchema)) modelBuilder.HasDefaultSchema(storeOptions.DefaultSchema); |
| 60 | + |
| 61 | + modelBuilder.Entity<PersistedGrant>(grant => |
| 62 | + { |
| 63 | + grant.ToTable("PersistedGrants"); |
| 64 | + |
| 65 | + grant.Property(x => x.Key).HasMaxLength(200).ValueGeneratedNever(); |
| 66 | + grant.Property(x => x.Type).HasMaxLength(50).IsRequired(); |
| 67 | + grant.Property(x => x.SubjectId).HasMaxLength(200); |
| 68 | + grant.Property(x => x.ClientId).HasMaxLength(200).IsRequired(); |
| 69 | + grant.Property(x => x.CreationTime).IsRequired(); |
| 70 | + grant.Property(x => x.Data).HasMaxLength(50000).IsRequired(); |
| 71 | + |
| 72 | + grant.HasKey(x => x.Key); |
| 73 | + |
| 74 | + grant.HasIndex(x => new { x.SubjectId, x.ClientId, x.Type }); |
| 75 | + }); |
| 76 | + |
| 77 | + modelBuilder.Entity<DeviceFlowCodes>(codes => |
| 78 | + { |
| 79 | + codes.ToTable("DeviceCodes"); |
| 80 | + |
| 81 | + codes.Property(x => x.DeviceCode).HasMaxLength(200).IsRequired(); |
| 82 | + codes.Property(x => x.UserCode).HasMaxLength(200).IsRequired(); |
| 83 | + codes.Property(x => x.SubjectId).HasMaxLength(200); |
| 84 | + codes.Property(x => x.ClientId).HasMaxLength(200).IsRequired(); |
| 85 | + codes.Property(x => x.CreationTime).IsRequired(); |
| 86 | + codes.Property(x => x.Expiration).IsRequired(); |
| 87 | + codes.Property(x => x.Data).HasMaxLength(50000).IsRequired(); |
| 88 | + |
| 89 | + codes.HasKey(x => new { x.UserCode }); |
| 90 | + |
| 91 | + codes.HasIndex(x => x.DeviceCode).IsUnique(); |
| 92 | + codes.HasIndex(x => x.UserCode).IsUnique(); |
| 93 | + }); |
| 94 | + } |
56 | 95 | }
|
57 | 96 | }
|
0 commit comments