【问题标题】:IdentityServer4 Introspection multi tenant requestIdentityServer4 Introspection 多租户请求
【发布时间】:2023-03-20 15:54:01
【问题描述】:

我正在尝试使用可用的自省示例 here 在请求中发送租户

var client = new HttpClient();
var tokenRequest = new PasswordTokenRequest {
    Address = disco.TokenEndpoint,
    ClientId = "roclient.reference",
    ClientSecret = "secret",
    UserName = "user",
    Password = "password",
    Scope = "api1 api2.read_only"
};
tokenRequest.Parameters.Add( "acr_values", "tenant:mytenant" );
var response = await client.RequestPasswordTokenAsync( tokenRequest );

但是,tenant 参数,服务器端始终为空,从下面的日志中可以看到

    [09:54:02 INF] User authentication failed: ["invalid_username_or_password"], request details: 
{
    "ClientId": "roclient.reference", 
    "ClientName": "Introspection Client Sample", 
    "GrantType": "password", 
    "Scopes": "api1 api2.read_only", 
    "AuthorizationCode": null, 
    "RefreshToken": null, 
    "UserName": "user", 
    "AuthenticationContextReferenceClasses": null, 
    "Tenant": null, 
    "IdP": null, 
    "Raw": {"acr_values": "tenant:mytenant", "grant_type": "password", "username": "user", "password": "***REDACTED***", "scope": "api1 api2.read_only", "client_id": "roclient.reference", "client_secret": "***REDACTED***"}, 
    "$type": "TokenRequestValidationLog"
}

在请求中发送租户参数的正确方法是什么?

【问题讨论】:

    标签: asp.net-core identityserver4 access-token


    【解决方案1】:

    您做对了,但 IdentityServer 不会自动解析令牌请求中的 acr_values。根据您想要执行的操作,您可以创建并注册 ICustomTokenRequestValidator 的实现,以便在接收到特定 acr_values 时执行特殊操作。虽然文档会让人们相信otherwise,但我认为这只是导致错字的复制粘贴工作的结果(它几乎与authorize endpoint page 上的acrs 相同)。

    要亲自查看是否属于这种情况,您可以先查看调用token request validator 的token endpoint,然后再使用token response generator 生成响应。如果您将TokenRequestValidator 与AuthorizeRequestValidator 进行比较,您会很快注意到它对acr_values 的处理方式不同(只是在每一页上按ctrl-f 'acr')。

    【讨论】:

    • 非常感谢。非常准确和简洁的答案。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-08
    • 2015-03-30
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 2021-04-23
    • 1970-01-01
    相关资源
    最近更新 更多