英文:
Authentication in Golang WebSocket application
问题
我正在尝试在一个主要使用WebSockets的应用程序中实现用户身份验证,但我不确定如何开始。
我正在使用Gorilla mux和websocket包。
我考虑过使用这里描述的方法(文件main.go和auth.go),但这种方法是否能够防止已认证的用户劫持彼此的sockets,就像这篇文章中描述的那样?
有人能否在Go中建议一个好的方法或包?
英文:
I am trying to implement user authentication in an application that primarily uses WebSockets, but I am unsure how to begin.
I am using the Gorilla mux and websocket packages.
I have thought about using the method described here (files main.go and auth.go), but does this approach secure against authenticated users somehow hijacking each others sockets like described in this article?
Can someone suggest a good method or package(s) in Go?
答案1
得分: 5
在将连接升级到WebSocket协议之前,按照普通HTTP请求的方式进行身份验证。使用您在普通HTTP请求中使用的方法或包。
WebSocket连接可以被劫持的程度与普通HTTP连接被劫持的程度相同。WebSocket协议在这方面没有引入任何新问题。
Socket.io是在WebSockets、长轮询和其他技术之上的一层,用于将事件从服务器发送到浏览器客户端。与Socket.io相关的问题不一定适用于直接使用WebSocket。
英文:
Authenticate as you would for a plain HTTP request before upgrading the connection to the WebSocket protocol. Use whatever methods or packages you would use for plain HTTP requests.
A WebSocket connection can be hijacked to the extent that a plain HTTP connection can be hijacked. The WebSocket protocol does not introduce any new issues here.
Socket.io is a layer above WebSockets, long-polling and other techniques for sending events from the server to a browser client. Issues with Socket.io do not necessarily apply to direct use of a WebSocket.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论