【问题标题】:Running migrations on PersistedGrants for Identity Server 4 fails在 PersistedGrants for Identity Server 4 上运行迁移失败
【发布时间】:2020-05-02 06:03:29
【问题描述】:

我正在尝试在 .Net Core 3.1 上设置一个新的 IS4 实例,但由于 PersistedGrants 上下文中的“Key”列似乎无效,因此运行初始化过程失败。

这在 .Net 3.0 中不会发生,我们尝试复制,假设这与 EF Core 3.1 有关,但是,我看不出它可能是什么。

生成的输出,如果通过 Add-Migrations 运行:

我不想实现我自己的 DbContext 实现,但这似乎是我必须走的路?

持久性赠款实体

https://github.com/IdentityServer/IdentityServer4/blob/master/src/EntityFramework.Storage/src/Entities/PersistedGrant.cs

【问题讨论】:

标签: .net-core identityserver4


【解决方案1】:

在我的项目中,我们将自己的实体添加到应用程序 DbContext:

public class PersistedGrant 
{
    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public virtual string Key { get; set; }

    public virtual string Type { get; set; }

    public virtual string SubjectId { get; set; }

    public virtual string ClientId { get; set; }

    public virtual DateTime CreationTime { get; set; }

    public virtual DateTime? Expiration { get; set; }

    public virtual string Data { get; set; }
}

并实现持久化存储:

public class PersistedGrantStore : IPersistedGrantStore
{
    Dal.MasterDbContext _dbContext;

    public PersistedGrantStore(Dal.MasterDbContext dbContext)
    {
        _dbContext = dbContext;
    }

    private PersistedGrant ToModel(Dal.PersistedGrant entity)
    {
        return new PersistedGrant()
        {
            ClientId = entity.ClientId,
            CreationTime = entity.CreationTime,
            Data = entity.Data,
            Expiration = entity.Expiration,
            Key = entity.Key,
            SubjectId = entity.SubjectId,
            Type = entity.Type
        };
    }

    public Task<IEnumerable<PersistedGrant>> GetAllAsync(string subjectId)
    {
        var grants = _dbContext.PersistedGrants.Where(x => x.SubjectId == subjectId)
            .ToList()
            .Select(x => ToModel(x));

        return Task.FromResult(grants);
    }

    ...

【讨论】:

  • 似乎是要走的路,希望我能像 POC 一样启动并运行它,到目前为止,POC 的主要论点是失败的,因为它只是开箱即用。谢谢。
猜你喜欢
  • 2020-05-01
  • 1970-01-01
  • 2020-05-27
  • 2015-07-30
  • 2017-03-30
  • 2018-07-23
  • 2019-04-18
  • 1970-01-01
  • 2020-12-27
相关资源
最近更新 更多