OpenAPITools / OpenAPITools/openapi-generator
[REQ] C# Make it possible to handle dynamic apikey tokens
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.
I have generated C# code that for an endpoint uses two ApiKeyTokens. My problem is that while one of them is basically static, the other one is dynamic and changes from call to call.
I have tried to implement my own TokenProvider (DynamicTokenProvider) but when I register it, I can see it it registered as a singleton. I do this:
config.UseProvider<DynamicTokenProvider, ApiKeyToken>();
and this happens:
_services.AddSingleton<TTokenProvider>();
_services.AddSingleton<TokenProvider<TTokenBase>>(services => services.GetRequiredService<TTokenProvider>());
This means my tokens are fixed in time. The constructor for DynamicTokenProvider is this:
public DynamicTokenProvider(IEconomicTokenProvider tokenSource)
: base(new ApiKeyToken[2] {
new ApiKeyToken(tokenSource.AppSecretToken, Client.ClientUtils.ApiKeyHeader.X_AppSecretToken, prefix: ""),
new ApiKeyToken(tokenSource.AgreementGrantToken.Value ?? "", Client.ClientUtils.ApiKeyHeader.X_AgreementGrantToken, prefix: "")
})
IEconomicTokenProvider holds the two tokens and it is using that implementation I can modify the token.
Describe the solution you'd like
I need a way to modify the ApiKeyTokens on a per call basis. I have found no workable solution so far. I am open for suggestions.
Describe alternatives you've considered
The above is the closest I have gotten without it actually working.
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 with the generated C# client's UseProvider<DynamicTokenProvider, ApiKeyToken>() registration and the shown singleton service setup. Trace how TokenProvider is used during requests and determine where per-call token changes can be supported. Done means both ApiKeyTokens can be updated for each call rather than fixed when the singleton is constructed.
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