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

18 Replies, 1783 Views

Hey! curl basic auth can feel finicky, but it’s usually just about getting the syntax right. The `-u` flag is the easiest way:
`curl -u username:password https://api.example.com`

If that doesn’t work, try encoding the credentials manually. You can use `base64` in your terminal:
`echo -n 'username:password' | base64`

Then slap that into the header:
`curl -H "Authorization: Basic <encoded_creds>" https://api.example.com`

And yeah, plain text creds are a no-go for production. Use env vars or a secrets manager.

Messages In This Thread



Users browsing this thread: 1 Guest(s)