在Identity Server 4中传递带有参考标记的其他数据 [英] Passing additional data with reference tokens in Identity Server 4
问题描述
我正在Identity Server上使用参考令牌,并希望将一些其他数据传递给客户端.
I am using reference tokens on my Identity Server and want to pass some additional data to the client.
我知道如何通过在Profile Service中设置声明来对JWT进行此操作,但是我找不到找到对引用令牌进行类似操作的方法.理想情况下,我希望将数据作为令牌json结果中的额外参数传递,如下所示:
I know how to do this with a JWT by setting claims in my Profile Service but I can't find a way to do something similar with reference tokens. Ideally I would like to pass my data as an extra parameter in the token json result like so:
{
"access_token": "...",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "api1",
"custom_property": "custom value"
}
推荐答案
您可以实现(并注册)ICustomTokenRequestValidator
接口,该接口可以帮助添加自定义响应参数:
You can implement (and register) the ICustomTokenRequestValidator
interface which could help adding custom response parameters :
public class DefaultClientClaimsAdder : ICustomTokenRequestValidator
{
public Task ValidateAsync(CustomTokenRequestValidationContext context)
{
context.Result.CustomResponse = new Dictionary<string, object>
{
{"hello", "world" }
};
return Task.FromResult(0);
}
}
在身份服务器应用程序的Startup.cs
中注册它:
Register it in Startup.cs
in identity server app:
services.AddTransient<ICustomTokenRequestValidator, DefaultClientClaimsAdder>();
自定义属性将包含在令牌响应中:
The custom property will include in token response :
这篇关于在Identity Server 4中传递带有参考标记的其他数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!