Who are you? And what are you allowed to do?
Authentication answers “Who are you?” Authorization answers “What are you allowed to do?”
| Method | How it works | Use it for | Watch out for |
|---|---|---|---|
| Password | Something you know | Normal logins | Weak or reused passwords. Always store them hashed with a slow, salted algorithm, never in plain text. |
| API key | A long secret string sent with each call | Server-to-server and developer APIs | Identifies an app, not a person. If leaked, anyone can use it. Rotate keys. |
| Basic auth | Username:password in a header, base64 encoded (not encrypted) | Quick internal tools | Only safe over HTTPS. Sends the password every time. |
| Bearer token | A token in the Authorization header: whoever holds it is trusted | Modern APIs (JWT, OAuth access tokens) | Treat the token like a password. Keep it short-lived. |
| Cookie session | A session id stored in a cookie | Websites | Set HttpOnly, Secure and SameSite flags. |
| MFA | Password plus another factor (phone code, app, security key) | Anything important | SMS codes can be hijacked. Apps and keys are stronger. |
| Model | Idea | Example |
|---|---|---|
| RBAC (role based) | Give permissions to roles; give users roles. | Role “support” can read tickets and refund up to ₹500. |
| ABAC (attribute based) | Decide using attributes of the user, the data and the situation. | A doctor can read a record only if the patient is in their ward and it is working hours. |
| ACL (access control list) | A list on each object saying who can do what. | A shared document: Asha can edit, Ben can view. |
| Scopes | Permissions written inside a token (see OAuth). | read:photos but not delete:photos |
| Situation | Code | Meaning |
|---|---|---|
| No credentials, bad password, expired token | 401 | I do not know who you are. Log in (and send a WWW-Authenticate hint). |
| Logged in, but the role is not enough | 403 | I know who you are, and the answer is no. |
| Too many tries | 429 | Slow down (see Rate Limiting). |
| Term | Meaning in easy words |
|---|---|
| Identity | Who someone is (a user id, an email, an app id) |
| Credential | The proof of identity: password, token, key, certificate |
| Authentication (AuthN) | Checking who you are |
| Authorization (AuthZ) | Checking what you may do |
| Role | A named bundle of permissions, like “admin” |
| Permission | One allowed action, like “delete user” |
| RBAC | Role-based access control |
| MFA / 2FA | Using two or more kinds of proof |
| Principle of least privilege | Give only the access that is really needed |
| Bearer token | A token that grants access to whoever carries it |
| Hashing | A one-way scramble used to store passwords safely (with salt) |
| Choice | We gain | We lose |
|---|---|---|
| Strong MFA | Much harder to break in | Extra step for the user, recovery is harder |
| Short token life | Stolen tokens stop working soon | More refreshes and logins |
| Fine-grained permissions | Tight control | Harder to manage and to explain |
| Check at the gateway only | One place, simple | Services behind it may trust too much |
/orders/42 to /orders/43 and sees a stranger's order.