OAuth
OAuth 2.0 is a standard for delegated authorization: it lets an application act on your behalf in another service without ever seeing your password. You log in at the service itself, approve a limited scope (“read repositories”, “view calendar”), and the application receives an access token that works only for that scope and only for a while. “Sign in with Google” adds OpenID Connect on top, which also tells the app who you are.
For data engineers, OAuth is how connectors pull from Salesforce, Google Analytics, HubSpot or GitHub, and how services authenticate to each other with the client credentials flow.
The four roles
You
The person whose data is being accessed.
The app
Wants access, for example a reporting tool or an ingestion connector.
Issues tokens
Logs you in and asks for consent. Okta, Entra ID, Auth0, Keycloak, Google.
The API
Holds the data and accepts access tokens.
Authorization code flow with PKCE
This is the flow to use for web apps, single-page apps, mobile and CLI tools. PKCE (Proof Key for Code Exchange, “pixie”) was first meant for mobile apps; OAuth 2.1 makes it required for every client.
| NO. | STEP | FROM | TO | TYPE | INFO |
|---|---|---|---|---|---|
| 1 | 01 | app | browser | REDIRECT | /authorize?response_type=code&client_id=reports&redirect_uri=…/callback&scope=repo:read&state=xyz&code_challenge=E9Mr…&code_challenge_method=S256 |
| 2 | 02 | browser | auth | LOGIN | user authenticates (password, passkey, MFA) and consents |
| 3 | 03 | auth | browser | REDIRECT | /callback?code=SplxlO…&state=xyz |
| 4 | 04 | app | auth | TOKEN | grant_type=authorization_code, code, redirect_uri, code_verifier=dBjf… |
| 5 | 04 | auth | app | TOKEN | {access_token, token_type: Bearer, expires_in: 3600, refresh_token} |
| 6 | 05 | app | api | CALL | Authorization: Bearer eyJ… → 200 OK |
- A reporting app wants to read your repositories. It must never see your password.
- The app makes a random code_verifier, keeps it secret, and sends only its hash (code_challenge) when it redirects your browser to the authorization server.
- You log in on the authorization server's own page and approve the requested scope, for example
repo:read. - The server redirects back to the app with a short-lived authorization code. The app checks that
statematches what it sent. - The app exchanges the code plus the original verifier for tokens, over a back channel. A thief who stole only the code cannot pass the hash check.
- The app calls the API with the access token. The API checks the token and its scope, not your password.
Which flow when
| Flow | Use for | Status in 2026 |
|---|---|---|
| Authorization code + PKCE | Any app acting for a user | The default |
| Client credentials | Service to service, no user (an Airflow DAG calling an internal API) | Current |
| Device authorization | TVs, CLIs without a browser (gh auth login, az login --use-device-code) |
Current |
| Refresh token | Getting a new access token without asking the user again | Current; rotate them |
| Implicit | Old SPAs: token returned in the URL | Removed in OAuth 2.1, don’t use |
| Resource owner password | App collects your password directly | Removed in OAuth 2.1, don’t use |
OAuth vs OpenID Connect vs JWT
- OAuth 2.0 answers “may this app do X?” It gives an access token for an API.
- OpenID Connect (OIDC) answers “who is this user?” It adds an ID token (always a JWT) and a
/userinfoendpoint. Use it for login. - JWT is just a token format. Access tokens are often JWTs, but they may also be opaque strings the API checks with the authorization server (token introspection).
Common mistakes
- Using the access token as proof of login. That’s what the ID token is for. An access token issued to another app could be replayed against yours.
- Skipping
stateor PKCE. That opens the door to CSRF and stolen authorization codes. - Loose redirect URIs. Register exact URIs. Wildcards let attackers redirect codes to themselves.
- Asking for broad scopes. Request the minimum (
repo:read, notrepo). Users and security reviews will thank you. - Storing refresh tokens like config. They are long-lived credentials. Keep them in a secrets manager and rotate them.
Learning Resources
- OAuth 2.0 Simplified: Aaron Parecki, free online book
- oauth.net and OAuth 2.1 draft
- RFC 6749: OAuth 2.0, RFC 7636: PKCE, RFC 9700: OAuth 2.0 Security Best Current Practice
- OpenID Connect Core
- An Illustrated Guide to OAuth and OpenID Connect: Okta
- OAuth 2.0 and OpenID Connect (in plain English): Nate Barbettini