带有 EntityFramework 的 IdentityServer3
IdentityServer3 with EntityFramework
我希望这是一个简单且容易解决的问题。
我已经在现有项目中安装了 IdentityServer3 并设法让 "in memory" 正常工作。
现在我连接到我的 UserManager。当我尝试进行身份验证时,出现此错误:
"One or more validation errors were detected during model generation:\r\n\r\nCormar.Sql.Claim: : EntityType 'Claim' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.ClaimsIdentity: : EntityType 'ClaimsIdentity' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.IdentityReference: : EntityType 'IdentityReference' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.Secret: : EntityType 'Secret' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.RefreshToken: : EntityType 'RefreshToken' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.Token: : EntityType 'Token' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.Scope: : EntityType 'Scope' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.ScopeClaim: : EntityType 'ScopeClaim' has no key defined. Define the key for this EntityType.\r\nClaims: EntityType: EntitySet 'Claims' is based on type 'Claim' that has no keys defined.\r\nClaimsIdentities: EntityType: EntitySet 'ClaimsIdentities' is based on type 'ClaimsIdentity' that has no keys defined.\r\nIdentityReferences: EntityType: EntitySet 'IdentityReferences' is based on type 'IdentityReference' that has no keys defined.\r\nSecrets: EntityType: EntitySet 'Secrets' is based on type 'Secret' that has no keys defined.\r\nRefreshTokens: EntityType: EntitySet 'RefreshTokens' is based on type 'RefreshToken' that has no keys defined.\r\nTokens: EntityType: EntitySet 'Tokens' is based on type 'Token' that has no keys defined.\r\nScopes: EntityType: EntitySet 'Scopes' is based on type 'Scope' that has no keys defined.\r\nScopeClaims: EntityType: EntitySet 'ScopeClaims' is based on type 'ScopeClaim' that has no keys defined.\r\n"
我认为这可能是因为我缺少一个包,所以我使用 NuGet 来安装 IdentityServer3.EntityFramework 但是这个没用。
有谁知道如何解决这个问题?
这很直接,你必须有 IdentityServer3.EntityFramework。我查看了源代码并看到了迁移 类,所以我只是简单地将实体添加到我的 DbContext 中,如下所示:
public DbSet<Client> Clients { get; set; }
public DbSet<ClientClaim> ClientClaims { get; set; }
public DbSet<ClientSecret> ClientSecrets { get; set; }
public DbSet<Consent> Consents { get; set; }
public DbSet<Scope> Scopes { get; set; }
public DbSet<ScopeClaim> ScopeClaims { get; set; }
然后我做了 add-migration
和 update-database
。这为我创建了表格,一切都是 tickity-boo
我希望这是一个简单且容易解决的问题。 我已经在现有项目中安装了 IdentityServer3 并设法让 "in memory" 正常工作。 现在我连接到我的 UserManager。当我尝试进行身份验证时,出现此错误:
"One or more validation errors were detected during model generation:\r\n\r\nCormar.Sql.Claim: : EntityType 'Claim' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.ClaimsIdentity: : EntityType 'ClaimsIdentity' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.IdentityReference: : EntityType 'IdentityReference' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.Secret: : EntityType 'Secret' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.RefreshToken: : EntityType 'RefreshToken' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.Token: : EntityType 'Token' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.Scope: : EntityType 'Scope' has no key defined. Define the key for this EntityType.\r\nCormar.Sql.ScopeClaim: : EntityType 'ScopeClaim' has no key defined. Define the key for this EntityType.\r\nClaims: EntityType: EntitySet 'Claims' is based on type 'Claim' that has no keys defined.\r\nClaimsIdentities: EntityType: EntitySet 'ClaimsIdentities' is based on type 'ClaimsIdentity' that has no keys defined.\r\nIdentityReferences: EntityType: EntitySet 'IdentityReferences' is based on type 'IdentityReference' that has no keys defined.\r\nSecrets: EntityType: EntitySet 'Secrets' is based on type 'Secret' that has no keys defined.\r\nRefreshTokens: EntityType: EntitySet 'RefreshTokens' is based on type 'RefreshToken' that has no keys defined.\r\nTokens: EntityType: EntitySet 'Tokens' is based on type 'Token' that has no keys defined.\r\nScopes: EntityType: EntitySet 'Scopes' is based on type 'Scope' that has no keys defined.\r\nScopeClaims: EntityType: EntitySet 'ScopeClaims' is based on type 'ScopeClaim' that has no keys defined.\r\n"
我认为这可能是因为我缺少一个包,所以我使用 NuGet 来安装 IdentityServer3.EntityFramework 但是这个没用。 有谁知道如何解决这个问题?
这很直接,你必须有 IdentityServer3.EntityFramework。我查看了源代码并看到了迁移 类,所以我只是简单地将实体添加到我的 DbContext 中,如下所示:
public DbSet<Client> Clients { get; set; }
public DbSet<ClientClaim> ClientClaims { get; set; }
public DbSet<ClientSecret> ClientSecrets { get; set; }
public DbSet<Consent> Consents { get; set; }
public DbSet<Scope> Scopes { get; set; }
public DbSet<ScopeClaim> ScopeClaims { get; set; }
然后我做了 add-migration
和 update-database
。这为我创建了表格,一切都是 tickity-boo