c# - AspnetBoilerplate IdentityServer - 配置存储
问题描述
故事背景
提示:如果您熟悉 abp + postgres + IdentityServer,则可以跳过此步骤,然后转到问题
我目前正在尝试使用 AspnetBoilerplate 实现身份提供程序。
为此,我执行了以下步骤:
- 我从ABP站点下载了 AspNet Core 3.x com 多页 Web 应用程序模板。
- 我将 EF 更改 为使用 Postgres。
- 然后我实现了IdentityServer,并带有一些额外的步骤来接受角度客户端令牌。
你可以在这里看到我的解决方案。
问题
此时我有一个功能身份提供程序,但客户端、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 上设置配置存储吗?
解决方案
也许问题是你在这里使用了一个接口?
.AddAbpPersistedGrants<IAbpPersistedGrantDbContext>()
它不应该是一个具体的类型吗?为什么需要这个接口?
推荐阅读
- java - Java swing:我调用了一次drawString,它多次打印了我的字符串
- php - 如果 Webhooks 和 Jobs Laravel 的 Stripe (iDEAL) 收费成功,则通知前端 Vue SPA
- python - Scipy余弦相似度与sklearn余弦相似度
- google-cloud-platform - 使用 Ansible playbook 在 google cloud (gcp) 中创建实例
- c - 如何模拟“聊天机器人”程序的类似终端的行为?
- javascript - 如何从其父组件访问自定义反应组件功能?
- vim - 防止vim跳转源码
- java - 如何使用 Cassandra Java Driver 为所有查询设置一致性级别?
- c# - 命名空间“Microsoft.AspNetCore.Mvc.Razor”中不存在类型或命名空间名称“RuntimeCompilation”
- c# - 无法让 SceneManagement 脚本工作