C# 如何将自定义属性添加到IdentityServer4 PersistedGrantStore
我们正在使用EntityFramework和SQL Server的IPersistedGrantStore的默认实现 我需要存储IP地址(以便在“登录”中获取“大致”位置数据)。此表似乎是这样做的最佳位置,因为它已经存储了客户端id、日期时间和刷新令牌的到期时间。是否可以扩展此功能并添加额外属性?如果我实现我自己版本的IPersistedGrantStore,我就不能“破坏”接口定义的契约并添加额外属性,甚至不能使用派生类(来自IdentityServer4.Models.PersistedGrant),因为这样也不会遵守接口C# 如何将自定义属性添加到IdentityServer4 PersistedGrantStore,c#,entity-framework,.net-core,identityserver4,C#,Entity Framework,.net Core,Identityserver4,我们正在使用EntityFramework和SQL Server的IPersistedGrantStore的默认实现 我需要存储IP地址(以便在“登录”中获取“大致”位置数据)。此表似乎是这样做的最佳位置,因为它已经存储了客户端id、日期时间和刷新令牌的到期时间。是否可以扩展此功能并添加额外属性?如果我实现我自己版本的IPersistedGrantStore,我就不能“破坏”接口定义的契约并添加额外属性,甚至不能使用派生类(来自IdentityServer4.Models.PersistedGr
是否有任何方法可以将属性添加到此表中,并在调用StoreAsync时更新授权存储实现以添加属性?只需像下面的代码一样实现您的
IPersistedGrantStore
,并且您可以完全控制持久授权,您可以向存储添加新列
public class PersistStore : IPersistedGrantStore
{
private readonly IPersistedGrandStoreService _persistedGrandStore;
public PersistStore(IPersistedGrandStoreService persistedGrandStore)
{
_persistedGrandStore = persistedGrandStore;
}
public Task StoreAsync(PersistedGrant grant)
{
return _persistedGrandStore.AddAsync(grant.ToPersistedGrantModel());
}
public async Task<PersistedGrant> GetAsync(string key)
{
var grant = await _persistedGrandStore.GetAsync(key);
return grant.ToPersistedGrant();
}
public async Task<IEnumerable<PersistedGrant>> GetAllAsync(string subjectId)
{
var grants = await _persistedGrandStore.GetAllAsync(subjectId);
return grants.ToPersistedGrants();
}
public Task RemoveAsync(string key)
{
return _persistedGrandStore.RemoveAsync(key);
}
public Task RemoveAllAsync(string subjectId, string clientId)
{
return _persistedGrandStore.RemoveAllAsync(subjectId, clientId);
}
public Task RemoveAllAsync(string subjectId, string clientId, string type)
{
return _persistedGrandStore.RemoveAllAsync(subjectId, clientId, type);
}
}
公共类持久存储:IPersistedGrantStore
{
私有只读IPersistedGrandStoreService_persistedGrandStore;
公共PersisteStore(IPersistedGrandStoreService persistedGrandStore)
{
_persistedGrandStore=persistedGrandStore;
}
公共任务StoreAsync(PersistedGrant授权)
{
返回_persistedGrandStore.AddAsync(grant.topersistedgrandmodel());
}
公共异步任务GetAsync(字符串键)
{
var grant=wait_persistedGrandStore.GetAsync(key);
return grant.ToPersistedGrant();
}
公共异步任务GetAllAsync(字符串主体ID)
{
var grants=wait _persistedGrandStore.GetAllAsync(subjectId);
返回grants.ToPersistedGrants();
}
公共任务RemoveAsync(字符串键)
{
返回_persistedGrandStore.RemoveAsync(键);
}
公共任务RemoveAllAsync(字符串subjectId、字符串clientId)
{
return _persistedGrandStore.RemoveAllAsync(subjectId,clientId);
}
公共任务RemoveAllAsync(字符串subjectId、字符串clientId、字符串类型)
{
返回_persistedGrandStore.RemoveAllAsync(subjectId、clientId、type);
}
}