我在我的Identity Server上使用参考令牌,并希望将一些其他数据传递给客户端。
我知道如何通过在Profile Service中设置声明来使用JWT进行此操作,但是我找不到使用参考令牌执行类似操作的方法。理想情况下,我希望将数据作为令牌json结果中的额外参数传递,如下所示:
{
"access_token": "...",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "api1",
"custom_property": "custom value"
}
您可以实现(并注册)ICustomTokenRequestValidator
可以帮助添加自定义响应参数的接口:
public class DefaultClientClaimsAdder : ICustomTokenRequestValidator
{
public Task ValidateAsync(CustomTokenRequestValidationContext context)
{
context.Result.CustomResponse = new Dictionary<string, object>
{
{"hello", "world" }
};
return Task.FromResult(0);
}
}
Startup.cs
在身份服务器应用程序中注册:
services.AddTransient<ICustomTokenRequestValidator, DefaultClientClaimsAdder>();
自定义属性将包含在令牌响应中:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句