首页 > 解决方案 > AspnetBoilerplate IdentityServer - 配置存储

问题描述

故事背景

提示:如果您熟悉 abp + postgres + IdentityServer,则可以跳过此步骤,然后转到问题

我目前正在尝试使用 AspnetBoilerplate 实现身份提供程序。

为此,我执行了以下步骤:

你可以在这里看到我的解决方案。


问题

此时我有一个功能身份提供程序,但客户端、api 资源和身份资源正在内存中运行,如您所见

//AuthConfigurer.cs#L45

services.AddIdentityServer()
          .AddDeveloperSigningCredential()
          .AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
          .AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
          .AddInMemoryClients(IdentityServerConfig.GetClients())
          .AddAbpPersistedGrants<IAbpPersistedGrantDbContext>()
          .AddAbpIdentityServer<User>();

所以现在我想把 then 放在 EF 中,为此我尝试了以下方法:

//SSODbContext.cs
using Microsoft.EntityFrameworkCore;
using Abp.Zero.EntityFrameworkCore;
using Coders.SSO.Authorization.Roles;
using Coders.SSO.Authorization.Users;
using Coders.SSO.MultiTenancy;
using Abp.Localization;
using Abp.IdentityServer4;
using IdentityServer4.EntityFramework.Interfaces;
using IdentityServer4.EntityFramework.Entities;
using System.Threading.Tasks;

namespace Coders.SSO.EntityFrameworkCore
{
    public class SSODbContext : AbpZeroDbContext<Tenant, Role, User, SSODbContext>, IAbpPersistedGrantDbContext, IConfigurationDbContext
    {
        /* Define a DbSet for each entity of the application */
        public DbSet<PersistedGrantEntity> PersistedGrants { get; set; }
        public DbSet<Client> Clients { get; set; }
        public DbSet<ApiResource> ApiResources { get; set; }
        public DbSet<IdentityResource> IdentityResources { get; set; }

        public SSODbContext(DbContextOptions<SSODbContext> options)
            : base(options)
        {
        }

        // add these lines to override max length of property
        // we should set max length smaller than the PostgreSQL allowed size (10485760)
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
            
            modelBuilder.Entity<ApplicationLanguageText>()
                .Property(p => p.Value)
                .HasMaxLength(100); // any integer that is smaller than 10485760

            modelBuilder.ConfigurePersistedGrantEntity();
        }

        public Task<int> SaveChangesAsync() => base.SaveChangesAsync();
    }
}

应用了新的迁移和更新数据库,然后我将服务调用更改如下:

services.AddIdentityServer()
          .AddDeveloperSigningCredential()
          .AddConfigurationStore<SSODbContext>()
          .AddAbpPersistedGrants<IAbpPersistedGrantDbContext>()
          .AddAbpIdentityServer<User>();

但没有用,知道如何在 AspNetBoilerplate 上设置配置存储吗?

标签: c#.net-coreentity-framework-coreidentityserver4aspnetboilerplate

解决方案


也许问题是你在这里使用了一个接口?

.AddAbpPersistedGrants<IAbpPersistedGrantDbContext>()

它不应该是一个具体的类型吗?为什么需要这个接口?


推荐阅读