I was able to get the Identity Server 3 to provide a customized Token Response by implementing the ICustomTokenResponseGenerator Interface and adding the required parameters in the Custom section of the tokenResponse.
Steps:
Implement the Interface
Register the Interface in the factory
This fix worked for me and i'm able to get the custom items in the token response.
//Interface Implementation
public class CustomTokenResponseGeneratorService: ICustomTokenResponseGenerator
{
protected ITokenService _tokenService;
public CustomTokenResponseGeneratorService(ITokenService tokenService)
{
_tokenService = tokenService;
}
public Task<TokenResponse> GenerateAsync(ValidatedTokenRequest request, TokenResponse response)
{
var patientID = 123;
response.Custom.Add("patient" , patientID);
response.Custom.Add("scope" , request.AuthorizationCode.Scopes.ToArray());
response.Custom.Add("need_patient_banner" , "false");
response.Custom.Add("encounter" , patientID);
response.Custom.Add("client_id" , request.AuthorizationCode.ClientId);
response.Custom.Add("smart_style_url" , "UNK");
return Task.FromResult(response);
}
}
Step2: Register the CustomTokenResponseGenerator in the Identity Server factory
//Token Service
factory.CustomTokenResponseGenerator = new Registration<ICustomTokenResponseGenerator, CustomTokenResponseGeneratorService>();
Reference: Interface Detail for Identity Server 3