【发布时间】:2019-12-28 00:14:55
【问题描述】:
我正在使用具有基于令牌的授权的 Identity Server 4。在这个阶段我还没有实现配置文件,但是现在 Identity Server 正在使用我的自定义 ResourceOwnerPasswordValidator 并且正在我的数据库中的 PersistedGrants 表中正确地保留授权。
问题是数据库未能保存我在此阶段应用的自定义声明。
要创建授权,我在密码验证器中执行以下操作:
public Task ValidateAsync(ResourceOwnerPasswordValidationContext context)
{
...
// validate the user using the context, then generate custom claims
var claims = new List<Claim> { new Claim() }; // add claims here
context.Result = new GrantValidationResult(user.Id.ToString(), "password", claims);
return Task.CompletedTask;
}
但是当在数据库中创建持久化声明时,数据列仅包含默认声明:
{
"CreationTime": "2019-08-21T16:38:18Z",
"Lifetime": 2592000,
"AccessToken": {
// audiences, issuer, creation time, etc...
"Claims": [
{
"Type": "client_id",
"Value": "myClient",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
}, {
"Type": "scope",
"Value": "myAPI",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
}, {
"Type": "scope",
"Value": "offline_access",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
}, {
"Type": "sub",
"Value": "16",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
}, {
"Type": "auth_time",
"Value": "1566405497",
"ValueType": "http://www.w3.org/2001/XMLSchema#integer"
}, {
"Type": "idp",
"Value": "local",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
}, {
"Type": "amr",
"Value": "password",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
}, {
"Type": "name",
"Value": "email@domain.com",
"ValueType": "http://www.w3.org/2001/XMLSchema#string"
}
],
},
}
我觉得解决方案是重载 grants 类以确保正确初始化数据属性,但我是 IDServer4 的新手,不知道如何执行此操作。
【问题讨论】:
标签: asp.net-core identityserver4