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
WebSocket auth on VertxCurrentContext not working #29919
Comments
Hm, I'm no websockets expert but I will try to look at the code in the |
I might be wrong but I think that the current identity should be set even if the CDI request context is already active, or? @sberyozkin @RoMiRoSSaN it would be great if you could test the fix in this branch: https://github.com/mkouba/quarkus/tree/issue-29919 (i.e. checkout the branch, build the project and run your app/reproducer) |
Thanks @mkouba :-), @RoMiRoSSaN can you check if the proposed fix addresses the problem ? |
@mkouba @sberyozkin Hello. I tested it localy. It works correct Only when WS class annotated @authenticated and JS ws request not contains token - throws unauthorized exeprtion
But I think if you need ws authorize you will send token always) and this exception is not error) Thanks!) |
For other peaople who need auth in WS Create reactive route
Create custom ServerEndpointConfig.Configurator
Create WS class
In JS
|
@sberyozkin is it ok? If so I can send a pull request. |
Thanks @RoMiRoSSaN! |
Thanks @mkouba for this fix. |
@RoMiRoSSaN Thanks your your code fragments. I spent hours trying to find out how to do this before stumbling on your post above. I am having trouble getting it to run because, I think, I might be using the incorrect classes (eg for ServerEndpointConfig, etc). I am fairly new to Java so I am not sure which Maven dependencies I should include. Would you be able to post the pom dependencies and imports please so I can be sure I am using the correct libraries? Are these the correct ones? <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-routes</artifactId>
</dependency> import io.quarkus.vertx.web.RouteFilter;
import io.vertx.ext.web.RoutingContext;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig; I am currently getting
which to me looks like I am using the wrong library, I think. I thought Quarkus used Jakarta Websockets. You can see I am very confused! Thanks, |
I just thought to say I was testing first without sending the token, expecting some kind of graceful rejection, or 401. Maybe it needs some error checking? Just guessing. I will test again tomorrow with the token and see what happens. |
@RoMiRoSSaN: OK, it seems I had the correct classes and the What I cant work out is how to setup the onOpen and onMessage methods so I can access the JWT to get the claims without throwing errors related to blocking. I have tried all sorts of combinations but I can't make sense of how the various bits of documentation fit together. I have made a SO post about this to surface your helpful code fragments and to seek help on getting it to work. Thanks again, |
Confirm that this approach works, For other people who is still struggling to implement this hack, I created a simple working example here: https://github.com/chat-socket/websocket-server/tree/oauth2-workaround |
@glmanhtu Thank you. :-) I will check this out over coming days. Much appreciated. |
Describe the bug
Hello. In my comman we use auth on WebSocket class by this hack
We make ws request such this
And WebSoket class such as
Last version when it works is 2.12.3.Final
It works by changes in this commit - Add proper identity propagation to WebSockets - File WebsocketCoreRecorder
After update to version 2.13 and higher it work only then used property
quarkus.vertx.customize-arc-context=false
In version 2.13 added changes from this commit CDI context propagation improvements for the reactive stack.
Now where is two CurrentContext implementations - ThreadLocalCurrentContext (ws auth works) and VertxCurrentContext (ws auth not work)
This code from WebsocketCoreRecorder
When uses ThreadLocalCurrentContext - requestContext.isActive() is false, and principal added in context
When uses VertxCurrentContext - requestContext.isActive() is always true, and user don`t added on context
Maybe fix this place, or create fix VertxCurrentContext?
Thank you for your job)
Expected behavior
No response
Actual behavior
No response
How to Reproduce?
No response
Output of
uname -a
orver
No response
Output of
java -version
No response
GraalVM version (if different from Java)
No response
Quarkus version or git rev
2.13+
Build tool (ie. output of
mvnw --version
orgradlew --version
)No response
Additional information
No response
The text was updated successfully, but these errors were encountered: