API Keys and Bearer
Lesson 43 of 47 in Coddy's Networking with the Terminal course.
Most APIs identify you with a header rather than a login form. The common shape is:
curl -s -H 'Authorization: Bearer YOUR_TOKEN' http://127.0.0.1:9132/meBearer means exactly what it sounds like: whoever bears this token is treated as you. There is no further check, no password, no second factor. A leaked token is a leaked account until it is revoked.
That has consequences for how you handle it. A token in a URL ends up in browser history and server logs, so it belongs in a header. A token in a shell command ends up in your shell history, which is why real scripts read it from an environment variable instead of hard-coding it.
Some APIs use a differently named header such as X-API-Key. The mechanics are identical: a secret string in a header, sent with every request.
Challenge
HardSend a token and confirm it arrived intact.
- Start the capture listener on port 9132
- Request
/mecarrying the headerAuthorization: Bearer t0ken - Print the authorization line from
req.txt
Expected output:
Authorization: Bearer t0kenTry it yourself
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Networking with the Terminal
6curl in Depth
Seeing the HeadersSaving ResponsesCustom HeadersStatus and Timingcurl Exit CodesRecap: curl Flags9Auth and Debugging
API Keys and BearerThe User AgentTimeouts and RetriesReading a FailureRecap: DebuggingPractice on your own: Terminal playground