Skip to content
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

Is there any middleware support where I can check if authentication is ok before the "connection" event fires on the socket? #66

Closed
tausifcreates opened this issue Aug 12, 2023 · 3 comments
Labels
question Further information is requested

Comments

@tausifcreates
Copy link
Contributor

tausifcreates commented Aug 12, 2023

I saw a similar feature in node js socketio server (middlewares). Also, where are the reserved events, such as "connection", "disconnect" etc?

@Totodore
Copy link
Owner

You can use the whole ecosystem of middlewares from tower-http that is available for Axum.
Check the use of CorsLayer in the chat example and you can do the same with the AsyncRequireAuthorizationLayer.

With that you will protect you're entire server. If you want to only protect a namespace you can do the same thing than in the chat example. You just need the SocketReq data that is in the socket.handshake struct. With that you will be able to get your headers/uri to access credentials.

@Totodore Totodore added the question Further information is requested label Aug 13, 2023
@tausifcreates
Copy link
Contributor Author

Thanks for your response. What about the reserved events that we can see in the node js socket io server, such as "connection", "disconnect" etc?

@Totodore
Copy link
Owner

There is no custom event for the moment, there is PR open to have a disconnect event #41. There is no connect event planned but the content of the handler will be trigger when you're socket is connected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants