-
Notifications
You must be signed in to change notification settings - Fork 6k
OAuth2 Client Credentials Flow: Getting access tokens in the service/data tier #6780
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
@fritzdj Are you aware of These |
Thanks @jgrandja. It does look like this would meet our needs if we were to do some refactoring and use |
What re-factoring changes are you referring to? Can you be more specific and provide details. The only place |
Hi @jgrandja. The workaround you propose with ServletOAuth2AuthorizedClientExchangeFilterFunction which provides integration with WebClient works well if you only have one authenticated client. I think that, what @fritzdj tries to propose is an easy way to get new access tokens if needed. I think there is no such way in spring security. The case where you have lot's of clients. A client use Oauth2 authentication with a provider (for example "google"). Spring security receive this Access tokens and Refresh tokens and store it in OAuth2AuthorizedClientRepository (which is an InMemory repository). You need this Access token to use a certain service offline. Also, as the OAuth2AuthorizedClientRepository is an InMemory repository there is no easy way to access that InMemory repository for other servers. There's the way to get the OAuth2AuthorizedClientRepository bean, get the access token and use it. This way, if the server reboot, you lost your access token. So, there should be a way to configure the access token and refresh token persistence. Correct me if I'm wrong or if there are some easy solution to solve this problem. |
@jgrandja, by "re-factoring" I meant in a web app (not Spring Security itself). In many legacy web applications, RestTemplate is used all over the place. Switching to WebClient would take some effort. I think there should be a way to just grab new access tokens in the service/data tier of a web application (for one to many authenticated clients) while using RestTemplate if desired. Good point by @kujaomega - if this only supports one authenticated client that will likely not work for us either in all cases. |
I am not sure if it is planned in the future, but I'd also like to be able to obtain access token through different mechanism. For example we are using Feign Client instead, so using In Spring Cloud Security we have |
Sorry for my misunderstanding @fritzdj regarding the re-factoring you mentioned. I understand your goal and it makes sense. Keep an eye out on #6811 as the goal there is to address re-use and likely resolve this issue at the same time. I'll keep this issue open either way until #6811 is resolved, which I'm planning on starting this week. |
Yes, that is correct but this was a quick workaround I provided and would not have this limitation when the real solution is in place, which is planned via #6811, #6683, a new ticket or a combination of these.
At the moment, we only provide an in-memory implementation of FYI, |
Summary
Currently there is a way to auto-wire OAuth2AuthorizedClientService in a component in the service/data tier to lookup the OAuth2AuthorizedClient. This works, but you would still need to use OAuth2AuthorizedClientArgumentResolver to resolve OAuth2AuthorizedClient in web-tier first. My suggestion is to make things more self-contained in service/data tier by allowing OAuth2AuthorizedClientService to get new access tokens if needed. I think Spring should allow new access tokens to be retrieved either way (in service/data tier OR web tier). We tried this with a custom service bean and it is working using some of the logic in OAuth2AuthorizedClientArgumentResolver.
fyi @jgrandja - see #6609
Example
Here is an example of a bean that could be created and used by OAuth2AuthorizedClientArgumentResolver (in the web tier) OR used by a class in the service/data tier to get new access tokens. This also has a temporary workaround to get around #6609 (where access token is never refreshed).
The text was updated successfully, but these errors were encountered: