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

18 Replies, 1462 Views

Hey! curl basic auth is pretty simple once you know the tricks. The `-u` flag is the standard way, but if it’s not working, try encoding the credentials manually:

`echo -n 'username:password' | base64`

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

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

Messages In This Thread



Users browsing this thread: 1 Guest(s)