Use cURL to authenticate with JWT Bearer tokens

Posted on January 17, 2021 at 6:25 pm

Example to pass the Bearer token in the Authorization header:

curl -H 'Accept: application/json' -H "Authorization: Bearer ${TOKEN}" https://api.website.com/v1/users

If you need to get the Bearer token use this:

curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' --data '{"username":"{username}","password":"{password}"}' https://api.website.com/v1/auth

You can use jq to parse the JSON output and get the token:

curl -s -X POST -H 'Accept: application/json' -H 'Content-Type: application/json' --data '{"username":"{username}","password":"{password}"}' https://api.website.com/v1/auth | jq -r '.token'

Receive updates via email

Other Posts

Updated Posts