'How to authenticate Socket.IO connection with httpOnly cookie

I have the following question. I have a NestJS back-end and a VueJS front-end. I want to notify the front-end when the back-end is done with a long running task. I thought using socket.io for this is a good solution.

I implemented the socket.io server on the back-end and the socket.io-client on the front-end and I can emit and receive messages.

At the back-end I use passport jwt for user authenthication and I save the user's JWT access_token inside a httpOnly (set-cookie) token. The front-end send the token (inside httpOnly cookie) with every request after successfull login.

Question: How can I send the access_token inside de httpOnly cookie to socket.io to authenticate the user and secure the connection?

Please provide me with some documentation or code examples. I'm stuck on this for 3 days.

Kind regards, Mike



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source