OpenAPITools / OpenAPITools/openapi-generator

[REQ][csharp-netcore] ApiTokenFactory on configuration to make hooking in auto refreshing JWT Tokens much easier

Open
#11,001 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.