OpenID Connect (OIDC)
In short: OpenID Connect is a layer on top of OAuth that answers: who is the user? OAuth only governs access to data; OIDC adds sign-in.
The problem
With “Sign in with Google” your site should learn who is signing in without ever seeing a password. OAuth alone gives only an access token, not a verified identity.
What OIDC adds
- The ID token: a JWT with claims such as
sub(stable user ID),iss(issuer),aud(audience),exp(expiry) and often email and name. - The provider signs it (Digital signature); the site verifies the signature with the provider’s public key.
- Standard scopes (
openid,profile,email) and a userinfo endpoint for more data.
Flow (code flow with PKCE)
- The site redirects to the provider with
scope=openid, a randomstateand a PKCE check value. - The user signs in there (ideally with MFA or Passkeys).
- The provider sends back a code.
- The server exchanges the code for ID and access tokens.
- The server checks signature,
iss,aud,expandnonceand creates the session.
Typical mistakes
- Verifying tokens in the browser instead of on the server.
- Not checking
audoriss. - Matching users by email instead of
sub(emails can change). - Omitting
state(CSRF risk).
Further reading: SSO.