【发布时间】:2020-08-04 02:40:07
【问题描述】:
故事背景
提示:如果您熟悉 abp + postgres + IdentityServer,则可以跳过此部分,然后转到 问题
我目前正在尝试使用 AspnetBoilerplate 实现身份提供程序。
为此,我做了以下步骤:
- 我从ABP 站点下载了 AspNet Core 3.x com 多页 Web 应用程序模板。
- 我改了EFto use Postgres。
- 然后我实现了IdentityServer,以及一些extra steps 来接受角度客户端令牌。
你可以看到我的解决方案here。
问题
此时我有一个功能性的身份提供者,但客户端、api 资源和身份资源都在内存中运行,你可以see:
//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 上设置配置存储吗?
【问题讨论】:
-
认为您必须更具体地说明什么不起作用,您是否将一些客户端和资源添加到数据库中?
-
这是问题所在,我无法在我的 EF 中正确设置 IdentityServer 配置存储。我需要我的应用程序使用配置存储,然后我可以使用数据库来设置我的客户端和资源。
-
你得到什么错误?
-
我尝试去发现文档端点
/.well-known/openid-configuration,我收到以下错误InvalidOperationException: No database provider has been configured for this DbContext. -
您是否已应用迁移并使用表格和内容填充数据库?你能连接到数据库吗?也许创建一个测试 DBContext 并对数据库进行一些测试查询,以确保它有效。
标签: c# .net-core entity-framework-core identityserver4 aspnetboilerplate