Is there any way to override identity server 4 token generation ? means a class or interface to get username and password to call an external services to get token then use it by identity server 4 ?
Is there any way to override identity server 4 token generation ? means a class or interface to get username and password to call an external services to get token then use it by identity server 4 ?
If I understand your question correctly then Yes, there are a couple of options.
You can create a custom ProfileService to call your external service when Claims are generated, you can then fetch data from you external service, then return a List<Claim> for the information you are interested in. You would write all that inside the GetProfileDataAsync(ProfileDataRequestContext context) method.
Then you register the profile service through identity server builder middleware
var identityServerBuilder = services.AddIdentityServer();
identityServerBuilder.AddProfileService<ProfileService>()
And when you use the access token i.e communication to a third party API, you can simply depend on HTTPContext to find a claim by name and get the value you need, i usually write a ClaimsProvider that has getter methods to return the claims i need and means i can mock it easily without having to consider mocking httpcontext. Something like this
It is possible to hook into the other parts of the lifecycle, check this for example: http://docs.identityserver.io/en/latest/topics/custom_token_request_validation.html I recommend that you read the documentation if this doesn't move you forward?
Have fun! :)