OpenAPITools / OpenAPITools/openapi-generator
[REQ][csharp-netcore] ApiTokenFactory on configuration to make hooking in auto refreshing JWT Tokens much easier
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the csharp-netcore Configuration class and the generated API code paths that read AccessToken. Trace how the singleton Configuration is used during requests, then verify that an injectable access-token producer can support refresh logic while preserving the current AccessToken behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100