Passing additional data with reference tokens in Identity Server 4

放肆的年华 提交于 2020-02-16 07:50:36

问题


I am using reference tokens on my Identity Server and want to pass some additional data to the client.

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"
}

回答1:


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);
    }
}

Register it in Startup.cs in identity server app:

services.AddTransient<ICustomTokenRequestValidator, DefaultClientClaimsAdder>();

The custom property will include in token response :



来源:https://stackoverflow.com/questions/57594234/passing-additional-data-with-reference-tokens-in-identity-server-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!