OAuth 2.0 and OpenID Connect: A Simple Guide to Secure Login
OAuth 2.0 is an authorization framework (RFC 6749) that lets an app get limited access to your data on another service without seeing your password, using short-lived access tokens. OpenID Connect (OIDC) is an identity layer built on top of OAuth 2.0 that adds authentication: it returns a signed ID token telling the app who you are. In short, OAuth answers what this app may do, and OIDC answers who this user is.
Topic: Active Directory & Identity Security in Cybersecurity & Ethical Hacking · Explainer
Also covers: Web & API Security
Quick answer: OAuth 2.0 is an authorization framework (RFC 6749) that lets an app get limited access to your data on another service without seeing your password, using short-lived access tokens. OpenID Connect (OIDC) is an identity layer built on top of OAuth 2.0 that adds authentication: it returns a signed ID token telling the app who you are. In short, OAuth answers what this app may do, and OIDC answers who this user is. The recommended pattern today is the authorization code flow with PKCE (RFC 7636), as described in the OAuth security best practice RFC 9700 and the OAuth 2.1 draft.
Key takeaways
- OAuth 2.0 is for delegated authorization, not login by itself.
- OIDC adds the ID token and a standard user info endpoint for login.
- Use the authorization code flow with PKCE for web, mobile and single-page apps.
- The implicit and password grants are deprecated in current best practice.
- OAuth 2.1 consolidates these rules but is still an IETF draft, not an RFC.
Table of Contents
- What Is the Difference Between OAuth 2.0 and OpenID Connect?
- Who Are the Parties in an OAuth Flow?
- How Does the Authorization Code Flow With PKCE Work?
- What Are Access, Refresh and ID Tokens?
- What Changes in OAuth 2.1?
- What Are the Common Security Mistakes?
- References
What Is the Difference Between OAuth 2.0 and OpenID Connect?
Think of a hotel. OAuth gives a valet a key card that opens only the car park, for a limited time. It does not tell the hotel who the valet is. OpenID Connect Core 1.0 adds an ID card: a signed statement from the identity provider about the user. Using a plain OAuth access token as proof of login is a known mistake, because tokens are meant for an API, not the client.
| Aspect | OAuth 2.0 | OpenID Connect |
|---|---|---|
| Purpose | Authorization (access to APIs) | Authentication (user identity) |
| Specification | RFC 6749 | OIDC Core 1.0 (OpenID Foundation) |
| Main token | Access token | ID token (a JWT) plus access token |
| Trigger | Requested scopes | The openid scope |
| Typical use | App reads your calendar | Sign in with an identity provider |
Who Are the Parties in an OAuth Flow?
RFC 6749 defines four roles: the resource owner (the user), the client (the app), the authorization server (issues tokens) and the resource server (the API). In OIDC the authorization server is called the OpenID Provider and the client is the relying party.
How Does the Authorization Code Flow With PKCE Work?
- The client creates a random code verifier and sends its hash (code challenge) with the authorization request, plus a state value.
- The user signs in at the authorization server, ideally with MFA, and approves the scopes.
- The server redirects back to a pre-registered redirect URI with a one-time authorization code.
- The client exchanges the code and the original code verifier for tokens over a back channel.
- The server checks the verifier matches the challenge, then issues tokens.
PKCE (RFC 7636) stops a stolen authorization code from being redeemed by another app. RFC 8252 requires it for native apps, and RFC 9700 recommends it for all clients.
What Are Access, Refresh and ID Tokens?
| Token | Audience | Purpose | Handling |
|---|---|---|---|
| Access token | Resource server (API) | Authorise API calls | Short lifetime, narrow scopes |
| Refresh token | Authorization server | Get new access tokens | Store securely; rotate or sender-constrain |
| ID token | Client | Prove user login | Validate signature, issuer, audience, expiry, nonce |
ID tokens are JSON Web Tokens defined in RFC 7519.
What Changes in OAuth 2.1?
The OAuth 2.1 Internet-Draft folds years of security fixes into one document. It requires PKCE for the authorization code flow, removes the implicit and resource owner password grants, requires exact redirect URI matching, and forbids access tokens in URL query strings. As of November 2026 it remains an active IETF draft, so cite RFC 6749 plus RFC 9700 for formal requirements.
What Are the Common Security Mistakes?
- Loose redirect URI matching, which can leak codes to an attacker-controlled page.
- Missing state or nonce checks, enabling login CSRF and token replay.
- Not validating ID token signature, issuer and audience.
- Over-broad scopes and long-lived tokens stored in browser local storage.
- Account linking by email without verification, as shown in our OAuth misconfiguration 2FA bypass example.
The OWASP OAuth 2.0 Cheat Sheet lists checks for developers. Strong MFA protocols at the identity provider protect every connected app. Security testing of OAuth deployments needs written authorisation under India’s IT Act 2000, Sections 43 and 66.
To build secure identity integrations, explore our application security training.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0