How do I properly use curl basic auth for API authentication?

18 Replies, 1772 Views

Hey ConfusedCoder!
curl basic auth isn’t too bad once you figure it out. The `-u` flag is the go-to, but if it’s not working, try this:

1. Encode your creds:
`echo -n 'username:password' | base64`

2. Use the encoded string in the header:
`curl -H "Authorization: Basic <encoded_string>" https://api.example.com`

And yeah, plain text creds are a security risk. Use environment variables or a .netrc file to keep ‘em safe.

Messages In This Thread



Users browsing this thread: 1 Guest(s)