【问题标题】:Identity Server 4 PersistedGrant Not Saving Custom ClaimsIdentity Server 4 PersistedGrant 不保存自定义声明
【发布时间】: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


    【解决方案1】:

    我最终实现了我自己的IProfileService,并在我的 ID4 启动中将其作为临时资源提供。接口实现的GetProfileDataAsync 函数允许您将声明添加到您希望作为授权方声明访问的用户配置文件。

    我仍然认为在密码验证器中添加的声明应该在没有额外代码的情况下传递。要求额外的配置文件服务将它们添加两次似乎是多余的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-16
      • 2018-10-06
      • 1970-01-01
      • 2018-10-16
      • 2015-05-29
      • 1970-01-01
      • 2017-05-14
      • 1970-01-01
      相关资源
      最近更新 更多