Websockets auth
See original GitHub issueI’m submitting a…
[ ] Regression
[ ] Bug report
[ ] Feature request
[ x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
There is no information about auth in websockets microservice in the docs. Can we use middlewares / interceptors / guards / nest-passport for it ?
@WebSocketGateway({
middlewares: [AuthenticationGatewayMiddleware]
})
But as I see it’s no longer supported, isn’t it?
- Guards
From the docs I understood that
guards
is like access policy. It executes before every method call and check permission to handler. But auth logic might not be here, isn’t it?
- Interceptors Interceptors is not called at connection time. Only on emiting, so I think it’s not our case.
handleConnection()
inside gateway. Is this is the place where auth might be?
Can you explain plz the best practices how to do it inside Nestjs ecosystem? 😉
Thanks.
Environment
[System Information]
OS Version : Linux 4.15
NodeJS Version : v8.9.1
NPM Version : 6.1.0
[Nest Information]
websockets version : 5.4.0
common version : 5.4.0
core version : 5.4.0
cqrs version : 5.1.1
Issue Analytics
- State:
- Created 5 years ago
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Authentication - websockets 10.4 documentation
Authentication #. The WebSocket protocol was designed for creating web applications that need bidirectional communication between clients running in browsers ...
Read more >WebSocket Token-Based Authentication - Nuvalence
Requests to authenticate are made to the HTTP endpoint /authenticate/token with the internal authentication token securely passed in the header of the request....
Read more >Websocket Security - authentication - Stack Overflow
To secure your messages, use WebSockets over SSL/TLS (wss:// instead of ws://). Don't roll your own crypto. Concerning authentication.
Read more >Authenticating Users Over WebSockets with JSON Web ...
In this guide, you will learn how to use Websockets and JSON Web Tokens, which are also ... By default, WebSockets lack authentication, ......
Read more >Authenticating Websockets - DEV Community
Generally speaking the Explicit Authentication Message strategy is a good choice for how to establish authentication on WebSocket connections.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is how I achieved it :
Guard :
Gateway :
Here is an example implementation:
Where on the client you would authenticate by passing ‘dummy’ headers in the
data
object like so: