-
Notifications
You must be signed in to change notification settings - Fork 6k
OAuth2 client integration with WebSocketClient #6711
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
I'm not proud of this, but what I ended up doing as a workaround (rather than copy/paste
Using this stream, I can reuse ExchangeFilterFunctions provided by spring security to generically obtain the Even though I have a workaround, I'd still rather spring-security-oauth2-client provide a generic mechanism that can be used to retrieve tokens that can be used in any outbound client. |
@philsttr Thanks for the report. This is the first request for oauth2 client support using I will see what I can do to extract logic out so it can potentially be reused in Let's leave this issue open and see if other users are looking for this type of integration. |
Hello, I start with a big "Thank you" to you! My use case is this one: I'm building a java code generator, to generate GraphQL client or server: https://github.com/graphql-java-generator/graphql-maven-plugin-project But perhaps this message could help to make this request be implemented ? Etienne |
@etienne-sf I'm still not seeing much demand for OAuth2 |
Yes, I understand. BTW, thanks to phillsttr, I have a working workaround. Étienne |
@philsttr I'm going to close this as there isn't much demand for OAuth2 If there are areas in the code that we could re-factor to allow for greater reuse and make it easier for you (and others) to work with |
Hey, I demand it )). Reopen plz! |
Precondition is my client id registration with registration id: johndoeservice my properties:
Getting JWT with Spring without filter:
I have the whole thing cached and also picked the expiration date from jwt. If a service wants the token from the cache shortly before it expires, the chache takes a new one. During websocket connect:
As result, you have the Auth Header in WebSocket connect. You can observe it with Wireshark. When SpringBoot receives this connect with invalid Header it denies. Otherwise it lets work. I tested it with SpringBoot 3.2.7 until 3.4.1 Drawback is that you have to care about expiration. Without caching you would call auth endpoint on every request. |
In spring-security-oauth2-client 5.1, OAuth2 client is supported fairly well with webflux's
WebClient
viaServerOAuth2AuthorizedClientExchangeFilterFunction
.However, there is no equivalent support for webflux's
WebSocketClient
. For example, I would like to:ClientRegistration
/OAuth2AuthorizedClient
ServerOAuth2AuthorizedClientExchangeFilterFunction
Authorization
header of the initial websocket outbound upgrade requestIn my application, I'm currently debating on whether I want to copy/paste
ServerOAuth2AuthorizedClientExchangeFilterFunction
and it's correspondingOAuth2AuthorizedClientResolver
(which is package-private) in order to provide similar support for my websocket use cases.It's really a shame that
WebSocketClient
does not useExchangeFilterFunction
s, otherwise we'd get this for free. Instead, it looks like I'll have to use reactor netty'sHttpClient.headersWhen
method as a hook to provide headers instead.At a minimum, it would be nice if most of the logic for obtaining an access token in
ServerOAuth2AuthorizedClientExchangeFilterFunction
was extracted out into a class that could be reused inExchangeFilterFunction
(for WebClient),Mono<OAuth2AuthorizedClient> OAuth2AuthorizedClientResolver.loadAuthorizedClient
is almost what I need. Except it doesn't handle refreshing tokens, and it's not public.The text was updated successfully, but these errors were encountered: