-
Notifications
You must be signed in to change notification settings - Fork 6k
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
Add OAuth + WebClient Support #4921
Comments
Here is some context : Spring Security OAuth 2 had support for Using WebClient requires the client to handle the token retrieval. Would be nice if that feature from |
I have an important request regarding that OAuth 2 support. Could it be packaged as a separate lib without the server related stuff? The main reason is that our SCS client using boot picks up Oauth2 dependencies transitively. This results in boot auto-configuring OAuth2 endpoints because the current jar has boot client and server classes altogether. |
The client and server(s) will be in separate modules. The client module is in |
Awesome ! |
…uthorizedClientRepository Issue: gh-4921
You can now provide the clientRegistrationId and ServerOAuth2AuthorizedClientExchangeFilterFunction will look up the authorized client automatically. Issue: gh-4921
…rizedClient Defaults to use the OAuth2AuthenticationToken to resolve the authorized client Issue: gh-4921
…xchange Leverage ServerWebExchange established by ServerWebExchangeReactorContextWebFilter Issue: gh-4921
Extract out a private API for shared code between the argument resolver and WebClient support. This makes it easier to make changes in both locations. Later we will extract this out so it is not a copy/paste effort. Issue: gh-4921
The authcodegrant samples were initially meant to be very simple demonstration of authorization code flow. However, it has become obvious since then that the real intent of the demo is how to use the WebClient with OAuth (there is no other reason to do authorization code flow unless you use the token to make a request). The samples have been migrated to oauth2webclient and oauth2webclient-webflux respectively. They have been improved: * The sample demonstrates usage with annotations, webclient directly, form login oauth2Login, and public APIs * The samples externalize the endpoint that is requested in the sample making it easier to try other endpoints * The UI no longer relies on a data structure for the result of the endpoint also making it easier to try other endpoints Issue: gh-4921
This is now resolved in master |
Does this support authorization grant type of Looking in |
@idc101 Thanks for the feedback. You are correct. We do not yet support password grant types. Please log an issue for support if you would like to see it |
WebClient Support
This is now resolved. Demo usage can be found in oauth2webclient and oauth2webclient-webflux samples. A quick tour of the support:
Built In WebClient Support
WebClient
has built in support for easily adding a Bearer token. For example:Why use Spring Security Extensions?
Spring Security provides first class support for OAuth2. A few advantages of using this support are:
Setup
The first step is ensuring to setup the
WebClient
correctly.For a Servlet environment this looks like:
For other (i.e. WebFlux) environments it looks like:
Implicit OAuth2AuthorizedClient
If we set defaultOAuth2AuthorizedClient to true in our setup and the user authenticated with oauth2Login (i.e. OIDC), then the current authentication is used to automatically provide the access token. This is convenient, but in environments where not all endpoints should get the access token, it is dangerous (you might provide the wrong access token to an endpoint).
Explicit OAuth2AuthorizedClient
You can also explicitly provide an
OAuth2AuthorizedClient
by setting it on the requests attributes. In the example below we resolve theOAuth2AuthorizedClient
using Spring WebFlux or Spring MVC argument resolver support. However, the user can choose to resolve theOAuth2AuthorizedClient
however they wish.clientRegistrationId
Alternatively, it is possible to specify the
clientRegistrationId
on the request attributes and theWebClient
will attempt to lookup theOAuth2AuthorizedClient
. If it is not found, one will automatically be acquired.Summary (original)
We should add OAuth + WebClient support. The support for using WebClient in a Servlet environment and WebFlux must be separate because:
This is going to be broken up into multiple issues:
The text was updated successfully, but these errors were encountered: