OAuth Gives Access. OpenID Connect Tells You Who Logged In.
Both buttons open a Google page, ask you to approve, and send you back. So people assume they are the same thing. They share a base, but they answer different questions.
- OAuth answers: what is this app allowed to do? It gives an access token for an API.
- OpenID Connect (OIDC) answers: who is this person? It adds an ID token that says who logged in.
OIDC is a layer on top of OAuth
OAuth alone has no standard way to tell your app who the user is. OIDC adds it. The flow is the normal OAuth flow, but the request must include the scope openid. Then the token response has an ID token next to the access token. "Sign in with Google" is usually OIDC: Google says its OAuth 2.0 APIs follow OpenID Connect.
{
"iss": "https://auth.example.com",
"sub": "24400320",
"aud": "my-app-id",
"exp": 1311281970,
"iat": 1311280970
}sub is the user’s ID at that provider, and the spec says it is never reassigned to another user. So store users by iss + sub, not by email. People change email addresses.
ID token for your app, access token for the API
The ID token names your app in aud. Your app reads it, checks it, and starts a session. The access token is for the API; your app sends it. Do not send one where the other belongs. One is a name badge, the other is a door key.
Many providers support both in one login. One approval can log the user in and connect their account.