I'm trying to achieve the same thing as the original poster. I want to use sec-websocket-protocol to pass a JWT auth token through when creating a websocket connection (as per the discussion here
https://stackoverflow.com/questions/4361173/http-headers-in-websockets-client-api). I want to do this so I can use our existing Pac4J authentication SecurityHandler rather than implement an additional authentication protocol just for websockets. This would help keep things simple and makes the security less fragile.
Note that I'm not expecting Vertx to provide this out of the box, just allow it to be possible by rolling my own handlers and so on. I was hoping to do this as follows:
1) Have a handler that replaces any "sec-websocket-protocol" request header is sees with an appropriate "authorization" header instead (as required by step #2).
2) Have the SecurityHandler validate/reject the token in the "authorization" header, exactly the same as for a normal HTTP request.
3) Upgrade or reject the websocket upgrade depending on whether the security check was successful.
4) Have a handler that writes the auth token back into the "sec-websocket-protocol" response header (to maintain compliance with the websocket spec).
I have some of the above parts working but am having trouble getting it working as a whole. I know the websocket handling in Vertx/Netty tries to deal with the "sec-websocket-protocol" header automatically which might get in the way, and I'm not sure whether context.addHeadersEndHandler() still gets called after a websocket.accept(). Before I spend too much time fighting issues like these, is the above approach a valid one or should I just give up and roll my own websocket auth protocol/messaging instead?
Many thanks,
Chris