如何进行websocket身份验证?

时间:2014-10-10 10:35:12

标签: javascript authentication websocket

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

1 个答案:

答案 0 :(得分:0)

你可以尝试

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将使其更好。 希望它能帮到你。这是我们构建FOREX系统的解决方案:通过CAS(单点登录)和Websocket进行身份验证以发送索引数据。在我们的例子中,CAS服务器将生成1个单点登录ID,我们使用它来验证。