reqwest
reqwest copied to clipboard
Allow to configure basic auth on the client instance
Currently, it doesn't seem to be possible to configure a client instance with a certain basic authentication header.
Constructing the header is not hard but requires a base64 dependency.
It would a good QoL improvement to make basic authentication configurable on the client builder.
It could be simply done. My initial worry is in making it so easy to accidentally send it to the wrong URL, if you share the Client. I guess the default headers part of Client already makes that possible, I don't know... Are there other clients offering similar options?
Are there other clients offering similar options?
ureq has an agent which is equivalent to reqwest's client that allows you to set basic auth: https://docs.rs/ureq/0.12.1/ureq/struct.Agent.html#method.auth
My initial worry is in making it so easy to accidentally send it to the wrong URL, if you share the Client.
If that is a serious concern, one way of going about it would be to add free functions to reqwest that allow you to build requests ad-hoc.
Currently, one has to instantiate a Client to do anything apart from get.
If you have to interact with several different URLs, that require different authentication, I think it is less likely to accidentally share credentials with the wrong server if the default way of using reqwest is without a client in the first place but rather through free-functions.
At the same time, it is inconvenient that there is no built-in way of having the same basic auth header with every request without implementing basic auth yourself.
Ok, so comming from requests and axios I really have missed this feature, not only for basic auth but things like bearer tokens and so on. In general auth is a tricky thing if not generalized and could be a lot easier if there would be a client side function.
Has there been any progress? Should I jump in and have a go to do something?
building patter:
- base URI
- auth
- time outs
- serialization
- ...