3

We're using clj-http to do HTTP basic authentication. I want to send a request with this header:

Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=

All the examples I've found say to do it like this:

(clj-http.client/get "http://my.domain.com" 
                     {:headers {:basic-auth [username password]}})

This seems to send a request that just contains a header called basic-auth, with unencoded values for username and password. I'm having to manually generate the basic auth header like this:

(clj-http.client/get "http://my.domain.com"
                     {:headers {:Authorization "Basic dXNlcm5hbWU6cGFzc3dvcmQ="}})

Of course, that's much harder because I have to encode the username and password properly and stick the word "Basic" on the front. Can clj-http do this for me?

Conan
  • 2,288
  • 1
  • 28
  • 42

1 Answers1

8

The :basic-auth key goes into the top level of the request map, not under :headers:

(clj-http.client/get "http://my.domain.com" 
                     {:basic-auth [username password]})
lnmx
  • 10,846
  • 3
  • 40
  • 36