API Key or OAuth? It Depends on Whose Data It Is
Before an API shares anything, it asks who you are. You will meet two answers all the time: an API key and OAuth. Pick by one question: whose data is this?
An API key is a house key
An API key is one long secret string from the service’s settings page. Like a house key, whoever holds it can get in. That is fine for your own account and your own data, with the key on your own server.
OAuth is the user saying yes
- Your app sends the user to the real site, like Google’s own login page.
- The user logs in there and sees what your app is asking for. Your app never sees the password. That is the whole point.
- If they say yes, your app gets a token for only those things.
- They can take it back later, without changing their password.
Where keys and tokens live
Both are secrets. They go in environment variables or a secret manager. Never in code, never in git. OAuth tokens also usually expire, so your code must know when.
From my own schedulerMy LinkedIn scheduler uses an OAuth token that lasts 60 days, with no refresh token. So I renew it by hand, and the code checks the expiry on every run and warns me by email.
Do this in 60 secondsOn GitHub, open Settings, then Applications, then Authorized OAuth Apps. If you see an app you no longer use, revoke it. That is the "take it back" half of OAuth.
Today’s AI angleAn AI agent acting for a user should get access the OAuth way, so the user can revoke it any time. Never paste a password into an agent. If it makes a mistake, a narrow token limits the damage.