badkins
2020-3-9 15:39:30

Is there an existing function to create a basic auth header given a username & password? I think it’s just a matter of joining the username & password with a colon, and base64 encoding that, but if there’s an existing function I’d use that.


badkins
2020-3-9 15:56:32

I suppose this will do: (define (create-basic-auth-header username password) (string-append "Authorization: Basic " (bytes->string/utf-8 (base64-encode (string->bytes/utf-8 (string-append username ":" password)) ""))))


samdphillips
2020-3-9 17:16:18

That’s pretty close to what I have in my bespoke unpublished http client package: (define (make-encoded-credential username password) (string-append "Basic " (bytes->string/utf-8 (bytes-trim-right-crlf (base64-encode (string->bytes/utf-8 (string-append username ":" password)))))))


samdphillips
2020-3-9 17:17:18

base64-encodeadds a crlf to the end of the bytes so I trim that off.


badkins
2020-3-9 17:21:07

If you pass a second arg of "", it won’t add the crlf


samdphillips
2020-3-9 17:36:43

Nice!