|
|
@ -6,6 +6,7 @@ |
|
|
|
|
|
|
|
|
using System; |
|
|
using System; |
|
|
using System.ComponentModel; |
|
|
using System.ComponentModel; |
|
|
|
|
|
using JetBrains.Annotations; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
|
|
using Microsoft.EntityFrameworkCore.Metadata.Builders; |
|
|
using OpenIddict.EntityFrameworkCore.Models; |
|
|
using OpenIddict.EntityFrameworkCore.Models; |
|
|
@ -26,7 +27,7 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization> |
|
|
where TToken : OpenIddictToken<TKey, TApplication, TAuthorization> |
|
|
where TKey : IEquatable<TKey> |
|
|
where TKey : IEquatable<TKey> |
|
|
{ |
|
|
{ |
|
|
public void Configure(EntityTypeBuilder<TApplication> builder) |
|
|
public void Configure([NotNull] EntityTypeBuilder<TApplication> builder) |
|
|
{ |
|
|
{ |
|
|
if (builder == null) |
|
|
if (builder == null) |
|
|
{ |
|
|
{ |
|
|
@ -37,28 +38,40 @@ namespace OpenIddict.EntityFrameworkCore |
|
|
// Entity Framework would throw an exception due to the TKey generic parameter
|
|
|
// Entity Framework would throw an exception due to the TKey generic parameter
|
|
|
// being non-nullable when using value types like short, int, long or Guid.
|
|
|
// being non-nullable when using value types like short, int, long or Guid.
|
|
|
|
|
|
|
|
|
|
|
|
// If primary/foreign keys are strings, limit their length to ensure
|
|
|
|
|
|
// they can be safely used in indexes, specially when the underlying
|
|
|
|
|
|
// provider is known to not restrict the default length (e.g MySQL).
|
|
|
|
|
|
if (typeof(TKey) == typeof(string)) |
|
|
|
|
|
{ |
|
|
|
|
|
builder.Property(application => application.Id) |
|
|
|
|
|
.HasMaxLength(50); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
builder.HasKey(application => application.Id); |
|
|
builder.HasKey(application => application.Id); |
|
|
|
|
|
|
|
|
builder.HasIndex(application => application.ClientId) |
|
|
builder.HasIndex(application => application.ClientId) |
|
|
.IsUnique(); |
|
|
.IsUnique(); |
|
|
|
|
|
|
|
|
builder.Property(application => application.ClientId) |
|
|
builder.Property(application => application.ClientId) |
|
|
|
|
|
.HasMaxLength(100) |
|
|
.IsRequired(); |
|
|
.IsRequired(); |
|
|
|
|
|
|
|
|
builder.Property(application => application.ConcurrencyToken) |
|
|
builder.Property(application => application.ConcurrencyToken) |
|
|
|
|
|
.HasMaxLength(50) |
|
|
.IsConcurrencyToken(); |
|
|
.IsConcurrencyToken(); |
|
|
|
|
|
|
|
|
builder.Property(application => application.Type) |
|
|
builder.Property(application => application.Type) |
|
|
|
|
|
.HasMaxLength(25) |
|
|
.IsRequired(); |
|
|
.IsRequired(); |
|
|
|
|
|
|
|
|
builder.HasMany(application => application.Authorizations) |
|
|
builder.HasMany(application => application.Authorizations) |
|
|
.WithOne(authorization => authorization.Application) |
|
|
.WithOne(authorization => authorization.Application) |
|
|
.HasForeignKey("ApplicationId") |
|
|
.HasForeignKey(nameof(OpenIddictAuthorization.Application) + nameof(OpenIddictApplication.Id)) |
|
|
.IsRequired(required: false); |
|
|
.IsRequired(required: false); |
|
|
|
|
|
|
|
|
builder.HasMany(application => application.Tokens) |
|
|
builder.HasMany(application => application.Tokens) |
|
|
.WithOne(token => token.Application) |
|
|
.WithOne(token => token.Application) |
|
|
.HasForeignKey("ApplicationId") |
|
|
.HasForeignKey(nameof(OpenIddictToken.Application) + nameof(OpenIddictApplication.Id)) |
|
|
.IsRequired(required: false); |
|
|
.IsRequired(required: false); |
|
|
|
|
|
|
|
|
builder.ToTable("OpenIddictApplications"); |
|
|
builder.ToTable("OpenIddictApplications"); |
|
|
|