OpenAPITools / OpenAPITools/openapi-generator
[BUG] Feign OAuth RequestInterceptor not caching access tokens
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When using the Feign Java client with OAuth2, a new access token is requested for each interaction, even though a valid and not yet expired access token is still in memory. I think the bug is located in this file:
In line 80 a current time in milliseconds is compared to the expiration time in seconds. This condition is true in (almost) all cases, so a new access token is requested for each API request.
openapi-generator version
I encountered this issue in version 6.0.1 and was able to work around it by downgrading to 5.4.0
OpenAPI declaration file content or url
Generation Details
very similar to https://github.com/OpenAPITools/openapi-generator/blob/master/bin/configs/java-feign-no-nullable.yaml
Steps to reproduce
- Use Feign with OAuth2 (in my case with an OauthClientCredentialsGrant)
- make request to API using generated client -> token is cached in variable
accessTokenand expiration time inexpirationTimeSeconds - send another request before
expirationTimeSecondsis reached ->updateAccessToken()is invoked although the token is not expired
Related issues/PRs
Suggest a fix
to
if (expirationTimeSeconds == null || System.currentTimeMillis() >= expirationTimeSeconds * MILLIS_PER_SECOND) {
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 in modules/openapi-generator/src/main/resources/Java/libraries/feign/auth/OAuth.mustache around line 80 and compare the millisecond time source with expirationTimeSeconds. Reproduce the Feign OAuth client-credentials flow by making two requests before expiration; done means the second request reuses the cached token instead of invoking updateAccessToken().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, authentication
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100