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.

May 13, 2025 - 12:47
Updated: 
101.5k

Active Directory & Identity Security in Cybersecurity & Ethical Hacking · Explainer

Web & API Security

OAuth 2.0 and OpenID Connect: A Simple Guide to Secure Login

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?

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.

AspectOAuth 2.0OpenID Connect
PurposeAuthorization (access to APIs)Authentication (user identity)
SpecificationRFC 6749OIDC Core 1.0 (OpenID Foundation)
Main tokenAccess tokenID token (a JWT) plus access token
TriggerRequested scopesThe openid scope
Typical useApp reads your calendarSign 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?

  1. The client creates a random code verifier and sends its hash (code challenge) with the authorization request, plus a state value.
  2. The user signs in at the authorization server, ideally with MFA, and approves the scopes.
  3. The server redirects back to a pre-registered redirect URI with a one-time authorization code.
  4. The client exchanges the code and the original code verifier for tokens over a back channel.
  5. 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?

TokenAudiencePurposeHandling
Access tokenResource server (API)Authorise API callsShort lifetime, narrow scopes
Refresh tokenAuthorization serverGet new access tokensStore securely; rotate or sender-constrain
ID tokenClientProve user loginValidate 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

No. OAuth 2.0 is for authorization; OpenID Connect adds authentication on top of it with a signed ID token.

PKCE, defined in RFC 7636, links the authorization request and token exchange with a secret verifier so stolen codes cannot be used.

Not yet. OAuth 2.1 is still an active IETF Internet-Draft; RFC 6749 and RFC 9700 remain the formal references today.

It returns tokens in the browser URL where they can leak, so current best practice uses the code flow with PKCE instead.

An ID token is a signed JWT from the OpenID Provider containing claims about the user, such as subject, issuer and audience.

The state parameter ties the response to the original request, which protects the redirect step against cross-site request forgery.

Store refresh tokens server side or in secure platform storage, rotate them on use, and avoid browser local storage.

Most modern social and enterprise sign-in buttons use OpenID Connect, though some older integrations use OAuth alone.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Vaishnavi

Vaishnavi is a skilled tech professional at the Ethical Hacking Training Institute in Pune, responsible for managing and optimizing the technical infrastructure that supports advanced cybersecurity education. With deep expertise in network security, backend operations, and system performance, she ensures that practical labs, online modules, and assessments run smoothly and securely. Her behind-the-scenes contributions play a vital role in delivering a seamless and secure learning experience for aspiring ethical hackers.