Javascript 如何进行websocket身份验证?

Javascript 如何进行websocket身份验证?,javascript,authentication,websocket,Javascript,Authentication,Websocket,我处理web应用程序,希望通过WebSocket向用户发送实时通知。这些通知只能由其通知所属的用户接收。 我想知道将临时身份验证令牌(对于用户来说是唯一的)传递给javascript,然后脚本连接到websocket服务器并将authtoken作为参数传递以进行握手是否是个好主意。将身份验证令牌传递给javascript,然后使用此身份验证令牌通过websocket登录,这是安全的解决方案吗?当然,web应用程序也由ssl和web套接字服务器保护。您可以尝试 User authenticate

我处理web应用程序,希望通过WebSocket向用户发送实时通知。这些通知只能由其通知所属的用户接收。 我想知道将临时身份验证令牌(对于用户来说是唯一的)传递给javascript,然后脚本连接到websocket服务器并将authtoken作为参数传递以进行握手是否是个好主意。将身份验证令牌传递给javascript,然后使用此身份验证令牌通过websocket登录,这是安全的解决方案吗?当然,web应用程序也由ssl和web套接字服务器保护。

您可以尝试

User authenticate to Web app Server
Web app Server will generate 1 Key Code for this session ( Maybe Md5 with salt is username) if user are valid
Web app Server send this key to Web Socket server 
Web app Server send this key to client-side
Client will send this key to websocket server to authenticate
If socket contained this key -> user is valid -> OK, continue to transfer data between socket and client, Else Web socket server will stop this connection.
它将是安全的,因为身份验证密钥是唯一的,SSL将使它更好。
希望对你有帮助。这就是我们构建外汇系统的解决方案:通过CAS(单点登录)和Websocket进行身份验证以发送索引数据。在我们的例子中,CAS服务器将生成一个单点登录ID,我们使用它来验证。

此会话的关键代码(可能带salt的Md5是用户名)
。我认为这是不安全的-有人可以只md5某人的用户名并向websocket服务器进行身份验证。我说的对吗?我用了“也许”。加密算法将是他的秘密。:)