Websockets proxy with session expiration #2209
-
Is the following currently possible with YARP? I'd like to setup YARP as a websockets proxy, where authentication is done by the proxy before forwarding to the outgoing endpoint. I'd also like the proxy to periodically check with another service if the authentication is still valid, and close the websocket connection if it has expired. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yes. Start with these docs: Which kind of auth? You may be able to hook into the auth events to set up the verification polling, or create a middleware for that. If you can determine the expiration up front that's even easier, just set up a timer to call HttpContext.Abort(), and cancel it if the request finishes Note that if you do decide to close the WS connection due to auth expiration/revocation, there's no easy way to do it gracefully (WebSocket Close message), it will be a connection abort. |
Beta Was this translation helpful? Give feedback.
Yes. Start with these docs:
https://microsoft.github.io/reverse-proxy/articles/websockets.html
https://microsoft.github.io/reverse-proxy/articles/authn-authz.html
Which kind of auth? You may be able to hook into the auth events to set up the verification polling, or create a middleware for that. If you can determine the expiration up front that's even easier, just set up a timer to call HttpContext.Abort(), and cancel it if the request finishes
HttpContext.RegisterForDispose(timer)
.Note that if you do decide to close the WS connection due to auth expiration/revocation, there's no easy way to do it gracefully (WebSocket Close message), it will be a connection abort.