在Golang WebSocket应用程序中进行身份验证

huangapple go评论75阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2015年2月11日 18:41:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/28452222.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定