What OAuth and OIDC are and how they work
OAuth 2.0 is a delegated access protocol: instead of a user’s password, an application gets a token with limited permissions and a limited lifetime from an authorization server. OpenID Connect (OIDC) is a layer on top of OAuth 2.0 that adds sign-in: the ID token tells the application who the user is and when they signed in.
Use OAuth when an application calls an API on behalf of a user, or a service calls an API on its own behalf. The user enters their password only at the authorization server, and the application receives a token for specific permissions that can be revoked without changing the password. If the frontend and the API are one application on one domain, OAuth between them is often unnecessary: a cookie-based session is enough, and OIDC remains a way to sign in through a provider.
OAuth defines four roles. The resource owner, usually the user, grants access. The client is the application that asks for access. The authorization server verifies the user and issues tokens, and the resource server, that is, the API, accepts requests carrying an access token. The client never sees the user’s password, and one authorization server can issue tokens for many APIs.
What OpenID Connect adds
OpenID Connect uses OAuth 2.0 messages and adds an ID token, a signed JWT with the user’s identifier and details of how they were authenticated, and a UserInfo endpoint that returns the profile. In OIDC the authorization server is called the OpenID Provider (OP) and the client is the Relying Party (RP): the application trusts the provider to verify the user and stores no passwords.
Authorization and authentication
OAuth answers the question “what is this application allowed to do?”: the access token is addressed to the API, and to the client it is an opaque string. OIDC answers the question “who is this user?”: the ID token is addressed to the client. A common mistake is to treat the user as signed in because the application received an access token. OAuth 2.0 alone does not tell the client who was authenticated or when, and that is what OIDC is for.
How it differs from a session and a password
| Approach | What it gives you | When to choose it |
|---|---|---|
| OAuth 2.0 | An access token with limited permissions; the password stays with the authorization server | An application or service calls an API on behalf of a user or on its own behalf |
| OpenID Connect | Sign-in through a provider: an ID token and the user’s profile | You need to know who the user is without storing their password |
| Cookie session | The application server keeps the sign-in state; the browser holds only the session cookie | The frontend and the API are one application on one domain |
| Password given to the application | The application stores the password and gets access to everything at once | Avoid it: the password leaks together with the application, and access can be revoked only by changing the password |
Choose OAuth when you need to give another application or service access to an API, and OIDC when you need sign-in through a provider. For an application on a single domain a session is enough, but OAuth still has advantages there: sign-in and two-factor checks live in the authorization server, and a new domain can be added without rework.
OAuth 2.1 is an IETF draft that combines OAuth 2.0 and common extensions in one document; see “Standards and their status” for the draft’s status. RFC 9700 dropped the implicit and password grants for OAuth 2.0 already; see “Flows” for why.
What to know first
- HTTP:
302redirects, theAuthorizationheader, status codes401and403— see the “HTTP and REST” reference - TLS: OAuth servers accept requests only over HTTPS — see the “TLS and PKI” reference
- JSON and base64url encoding: tokens and server responses are built from them
Section sources
the section is written from these pages- RFC 6749: The OAuth 2.0 Authorization Framework — 1. Introductionrfc-editor.org/rfc/rfc6749.html(opens in a new tab)
- How OpenID Connect Works - OpenID Foundationopenid.net/developers/how-connect-works/(opens in a new tab)
- OAuth 2.0 — OAuthoauth.net/2/(opens in a new tab)
- OpenID Connect Core 1.0 incorporating errata set 2: 1. Introductionopenid.net/specs/openid-connect-core-1_0.html(opens in a new tab)
- RFC 10017: OAuth 2.0 for Browser-Based Applications — 7.1. Single-Domain Browser-Based Applications (Not Using OAuth)rfc-editor.org/rfc/rfc10017.html(opens in a new tab)