IdentityServer4 ConfigurationDbContext未加载客户端机密

问题描述 投票:2回答:1

我想在烘焙到使用EntityFramework的我的IdentityServer项目的MVC应用程序的仅管理员页面中显示客户端及其秘密的列表。

我目前在依赖项注入中已在我的控制器中引用ConfigurationDbContext,并且可以访问客户端详细信息。但是,从上下文返回的每个客户端的ClientSecrets属性没有加载机密,并且设置为null。如何强制上下文加载存储在另一个表中的ClientSecrets?我应该采取其他方法吗?

entity-framework identityserver4 eager-loading
1个回答
0
投票

IdentityServer不会向您返回实体的许多属性。那是设计使然。如果希望客户实体具有特定的属性,则必须使用实体框架的扩展方法-Include

public class ApplicatonsService : IApplicationsService
{
    private readonly ConfigurationDbContext is4Context;

    public ApplicatonsService(ConfigurationDbContext is4Context)
    {
        this.is4Context = is4Context;
    }

    public Task<List<Client>> GetApplicationsAsync()
    {
        return Task.FromResult(is4Context.Clients
                .Include(c => c.ClientSecrets)
                .Select(c => c.ToModel()).ToList());
    }
    ...

}
© www.soinside.com 2019 - 2024. All rights reserved.