问题
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