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

18 Replies, 1475 Views

Yo! curl basic auth is pretty straightforward once you get the hang of it. The `-u` flag is your friend here. Just do:
`curl -u yourusername:yourpassword https://api.example.com`

If it’s still not working, double-check if the API expects the credentials in the header. Sometimes you gotta manually add the Authorization header like this:
`curl -H "Authorization: Basic $(echo -n 'username:password' | base64)" https://api.example.com`

And yeah, plain text creds are risky. Use a .netrc file or something to keep ‘em safe.

Messages In This Thread



Users browsing this thread: 1 Guest(s)