[REQ][csharp-netcore] ApiTokenFactory on configuration to make hooking in auto refreshing JWT Tokens much easier
Created by: RubberChickenParadise
Is your feature request related to a problem? Please describe.
Currently there is no good way to change out the Bearer access token after initialization of the Configuration when using Microsoft.Extensions.DependentyInjection
with a singleton Configuration object.
Describe the solution you'd like
After looking at the code, adding an Access Token producer Func which defaults to returning the Access Token property would enable end users to easily customize the Access Token producer with advanced logic, such as checking the expiration of the JWT then calling the Security Token Service to silently refresh the JWT.
Describe alternatives you've considered
An alternative would be to have the Configuration be a Scoped service but even that leads to issues if used in a long running scope (think WinForms desktop app)
A transient scope with a configuration constructor method to handle refreshing the token would be another possibility but that has the additional complication of requiring all the API classes be registered as transient as well, however that has the initialization overhead every time an instance of the API classes is requested.
Additional context
Just adding the Func GetAccessToken {get;set;} => ()=> AccessToken; then calling GetAccessToken instead of the property access would enable a much more configurable configuration object with minimal changes.