[英]AspnetBoilerplate IdentityServer - Configuration Store
TIP : You could skip this if you are familiar with abp + postgres + IdentityServer, and go to Question提示:如果您熟悉 abp + postgres + IdentityServer 和 go 来提问,则可以跳过此步骤
I am currently trying to implement an identity provider using the AspnetBoilerplate.我目前正在尝试使用 AspnetBoilerplate 实现身份提供程序。
For this I did the following steps:为此,我执行了以下步骤:
You could see my solution here .你可以在这里看到我的解决方案。
At this point I have an functional Identity Provider, but the clients, api resources and identity resources are running in memory as you could see :此时我有一个功能性身份提供程序,但客户端、api 资源和身份资源正在 memory 中运行,如您所见:
//AuthConfigurer.cs#L45
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddInMemoryIdentityResources(IdentityServerConfig.GetIdentityResources())
.AddInMemoryApiResources(IdentityServerConfig.GetApiResources())
.AddInMemoryClients(IdentityServerConfig.GetClients())
.AddAbpPersistedGrants<IAbpPersistedGrantDbContext>()
.AddAbpIdentityServer<User>();
So now I want to put then in EF, for that I tried the following:所以现在我想把 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();
}
}
Applied a new migration and update database, then I changed the service call as following:应用了新的迁移和更新数据库,然后我将服务调用更改如下:
services.AddIdentityServer()
.AddDeveloperSigningCredential()
.AddConfigurationStore<SSODbContext>()
.AddAbpPersistedGrants<IAbpPersistedGrantDbContext>()
.AddAbpIdentityServer<User>();
but didn't work, any idea how to setup Configuration Store on AspNetBoilerplate?但没有用,知道如何在 AspNetBoilerplate 上设置配置存储吗?
Perhaps the problem is that you use an interface here?也许问题是你在这里使用了一个接口?
.AddAbpPersistedGrants<IAbpPersistedGrantDbContext>()
Should it not be a concrete type instead?它不应该是一个具体的类型吗? Why do you need to have this interface?
为什么需要这个接口?
I solved this issue creating my own Stores in Application project inheriting from IdentityServer Stores interfaces, like the Scott Brady said in his blog (Article: Creating Your Own IdentityServer4 Storage Library).我解决了这个问题,在继承自 IdentityServer Stores 接口的 Application 项目中创建自己的 Stores,就像 Scott Brady 在他的博客(文章:创建您自己的 IdentityServer4 存储库)中所说的那样。
And then I added my stores in Startup like:然后我在 Startup 中添加了我的商店,例如:
services.AddIdentityServer()
// existing registrations
.AddClientStore<ClientStoreAppService>()
.AddCorsPolicyService<CorsPolicyService>()
.AddResourceStore<ResourcesStoreAppService>()
.AddPersistedGrantStore<PersistedGrantStoreAppService>()
.AddDeviceFlowStore<DeviceFlowStoreAppService>();
Step by step一步步
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.