-
-
Notifications
You must be signed in to change notification settings - Fork 530
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP Digest authentication #784
Comments
If I remember correctly Digest Authentication requires two HTTP requests: one to get the challenge from the server, one to send the response and open the websocket connection. If I had to do this, here's what I'd try:
It would be interesting to build this into websockets. Since we already handle basic auth and http redirects, I think we have all the pieces we need. |
It's a little more complex than that. The I don't know how that fits into websockets. It may be that we can do it just once and then after the upgrade there's no need. I'll do some experiments on Monday. |
In a WebSocket connection you send HTTP headers only once. After you've upgraded from a HTTP to a HTTP connection you're fine. |
Two options have been discussed for adding digest authentication support:
Option 1 is disfavored by the maintainer because it adds a dependency to websockets which currently has none. @Nicolas-Feude has done some great work in #1111 toward option 2. However, looking at the code in #1111, it would seem to add a lot of complexity to this package, and duplicates code from requests which may diverge over time. It also seems fraught to re-implement security-related code. I'm wondering if another option would be to use a library for the digest authentication but as an optional dependency. When digest authentication is required, websockets could output a message saying that the dependency needs to be installed. Digest authentication is an uncommon need, so it may be reasonable for the user to have to install an extra package to support it. (Not an experienced Python developer so unsure whether this is a good idea, but wanted to suggest it just in case.) |
Unfortunately #1111 isn't on the right track for the following reasons so I'm closing it. First, it targets the legacy implementation. However, I'm not adding new features to that implementation. The feature should target the new asyncio and threading implementation. Second, the fundamental design problem lies in how we handle HTTP sequences prior to the WebSocket handshake. Currently, websockets supports only one request and one response while Digest Authentication requires two. That sequence is handled in each I/O layer because validating credentials may require I/O e.g. if you want to check them in a database. This makes it more expensive to implement and to test than if it was in the Sans-I/O layer. I'm wondering if there's a way to redesign, at least on the client side, to move authentication logic to the Sans-I/O layer? On one hand, I'm very unsure that it can work; on the other hand, it could bring the cost of building and maintaining that feature down to a level where I'm willing to take it. Overall, I'm not planning to make websockets a full-featured HTTP client, yet HTTP features are creeping on the client side e.g. supporting proxies, redirects, etc. I resist taking a dependency on a full-featured HTTP client because it could create more complexity that I'm willing to deal with. The above is heavily influenced by the fact that I'm a solo maintainer and this is a hobby project. While I believe that it's a high quality hobby project, this quality depends on keeping the maintenance workload load very low. |
While #788 also targets the legacy implementation — which was the only implementation until the the Sans-I/O implementation landed one year later — there's a couple interesting ideas in there:
|
Since the authentication is embedded in the WebSocket handshake, we cannot replicate the design used for proxies — connecting a socket then handing it over to websockets. |
Hi folks,
How can I create a websocket client where the server requires digest authentication?
The text was updated successfully, but these errors were encountered: