-
Notifications
You must be signed in to change notification settings - Fork 6.1k
WebClient + OAuth 2.0 client - token isn't saved #7880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@altro3 I believe the issue is related to your configuration as the previously fetched token should be reused on subsequent requests. This feature has been working for quite some time now. The best approach to determine the issue you are having is if you could provide a minimal sample that reproduces the issue. I can then troubleshoot from the sample and provide you a fix. |
@jgrandja Hi! Thanks for your answer. I created sample project here: https://github.com/altro3/spring-oauth-test For test you can use any OAuth 2.0 server, I used paypal OAuth for test. To run test use this command .\gradlew clean build -i You need to change these settings before run test: class org.sping.oauthtest.OauthConfig .clientId("")
.clientSecret("")
.tokenUri("https://api.sandbox.paypal.com/v1/oauth2/token") Class org.sping.oauthtest.OauthClient .method(HttpMethod.GET)
.uri("https://api.sandbox.paypal.com/v1/catalogs/products") |
@jgrandja Yes, it works fine in with version 5.2.2. Thanks for help! 👍 |
Uh oh!
There was an error while loading. Please reload this page.
Summary
I wrote a client for PayPal, they use OAuth 2.0 for security. I decided to try applying your solution to webFlux WebClient. Your solution works and is quite convenient to use. But, the problem is that the received token is not saved and is requested from the server with each request.
Take a look at the example below. The logs show that before each request, another request is added, which is sent to the server in order to get the token, although the request for the token should be sent only before the first request to the server and the previously received token should be used for the next requests.
Actual Behavior
The token is not stored in memory and a request for a token is sent before each request to the server
Expected Behavior
The request for the token will occur only 1 time and the next time the token will be requested when it expires
Configuration
See example
Version
SpringBoot 2.2.3 and "org.springframework.security:spring-security-oauth2-client:5.2.1.RELEASE"
Sample
This is my sample:
Service
And Test
And what you can see in logs:
The text was updated successfully, but these errors were encountered: