有没有一个 Golang Websocket 库可以让我修改初始请求/选择 http.Client?

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

Is there a Golang Websocket library that would let me modify the initial request / let me pick the http.Client?

问题

我想连接到一个WebSocket服务器,但该端点是Kerberos身份验证的。我有一个能够进行Kerberos身份验证的库,还有一个http.Client包装器,可以对发送到任何端点的所有请求进行身份验证。

然而,我的这两个工具似乎对gorilla/websocket没有用处。我尝试了一些方法,包括发送一个经过身份验证的GET请求,然后将响应头传递给websocket.DefaultDialer.Dial(),但这并不起作用,因为实际的握手请求本身并没有经过身份验证。

因此,我感到困惑。有人有关于如何完成这个任务的想法吗?

英文:

I want to connect to a websocket server, but the endpoint is Kerberos authenticated. I have a library that is able to Kerberos authenticate requests, and I also have an http.Client wrapper that authenticates all requests sent through it to whatever endpoint.

Neither of my tools seem to be of any use with gorilla/websocket. I've tried a few things, including sending an authenticated GET request, then passing the response headers into websocket.DefaultDialer.Dial(), but that doesn't work since the actual handshake request itself isn't authenticated.

Hence, I am perplexed. Does anyone have ideas on how this can be done?

答案1

得分: 1

我弄清楚了。这是我所做的:

  1. 我向服务器发送一个经过Kerberos身份验证的GET请求,请求的目标是任何经过身份验证的端点。
  2. 然后我对响应进行身份验证并获取Cookie。
  3. 我创建一个经过Kerberos身份验证的GET请求,目标是websocket端点,并将Cookie添加到请求头中。
  4. 然后我通过gorilla/websocket进行拨号。

问题出在对Cookie的处理上。我将答案留在这里,以防其他人在使用Kerberos或其他身份验证服务时遇到类似的问题。

英文:

I figured it out. Here is what I do:

  1. I send a Kerberos-authenticated GET request to any authenticated endpoint on the server.
  2. I then authenticate the Response and grab the Cookie.
  3. I create a Kerberos-authenticated GET request to the websocket endpoint and add the Cookie to its header.
  4. Then I dial via gorilla/websocket

The issue was the treatment of the cookie. Leaving the answer here in case people run into similar troubles with Kerberos or other auth services.

huangapple
  • 本文由 发表于 2021年8月15日 06:25:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/68787444.html
匿名

发表评论

匿名网友

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

确定