On this page
What you need first
This lesson uses ideas from these earlier lessons. Read them first if any idea is new to you.
01Why interviewers ask this
The interviewer says: "Staff log in once and reach ten apps. How?" A weak answer is "we use a standard login tool". A strong answer says who talks to whom, and why a thief who copies the browser address gets nothing.
02The idea in plain words
A valet key starts the car but does not open the boot. The owner gives it to the parking helper and keeps the master key. "Log in with Google" on an app works the same way.
OAuth 2.0 is a standard that lets an app get limited access to your data on another service, without your password. It has four roles. The resource owner is you. The client is the app that wants access. The authorization server logs you in and issues tokens. The resource server is the API that holds your data.
The key is an access token (lesson 99). It carries scopes, a list of what it allows, such as "read my email". OAuth says what the client may do, not who you are.
OpenID Connect adds login. The client asks for the scope openid and also gets an ID token. This is a JWT (lesson 99) with claims: iss is who issued it, sub is the user ID, aud is the client it is for, and exp is the end time. The client checks the signature, iss, aud and exp.
The common flow is the authorization code flow with PKCE (Proof Key for Code Exchange):
- The client makes a random code verifier. The hash of it (lesson 99) is the code challenge.
- The client sends the browser to the authorization server. It adds its client ID (its name there), scopes, challenge, a random state that comes back unchanged, and a redirect URI: the address to send the browser back to. The server accepts only an address registered before.
- You log in and agree at the authorization server. The client never sees your password.
- The server sends the browser back to the redirect URI with a one-use code and the same state.
- The client checks the state. This makes sure that the reply answers its own request.
- The client sends the code and the verifier over HTTPS (lesson 7) to the token endpoint, where the server swaps a code for tokens. If the hash of the verifier matches the challenge, the server sends tokens.
The code passes through the browser, where others may copy it. It is useless without the verifier, which never passes through the browser. A phone app cannot keep a secret in its code. PKCE needs no secret, and RFC 9700 advises it for every client.
The client credentials flow is for one service calling another: it sends its own ID and secret and gets a token, with no user. Avoid the old implicit flow, which sends tokens through the browser, and never use the password flow, which gives your password to the client.
Single sign-on (SSO) means one login opens many apps. A company runs one identity provider (the authorization server above) and each app sends you to it. You log in once, and the provider keeps a session cookie. The next app gets a code with no password. SAML is an older standard for the same job.
Stuck on something? The AI tutor has read this lesson. Ask it with a free account
03Pause and predict
Pause. Guess first.
A thief copies the code from the redirect URL a moment after your browser gets it. Can the thief get tokens?
Write your guess before you read on. The answer is in the worked example.
04Worked example
A company has 2,000 staff and 5 internal apps. Assumptions (made up): each person opens each app once a day.
- The staff app makes a random verifier of 32 bytes, which is 32 x 8 = 256 bits. It sends the hash as the challenge.
- Asha logs in. The browser returns to
https://staff.example.com/callback?code=abc&state=Xk3. The app checksXk3, sendsabcand the verifier, and gets an access token and an ID token. - A thief with only
abccalls the token endpoint. The server hashes what the thief sends, and it does not match the challenge. The request fails. This answers the predict box. - Asha opens a second app. The provider sees its cookie and returns a code.
Logins in a day. Without SSO: 2,000 x 5 = 10,000. With SSO: 2,000. That is 10,000 / 2,000 = 5 times fewer.
05Trade-offs
OpenID Connect solves sharing passwords with apps, and gives one login. It costs extra redirects and a provider that must stay up. I would change to my own login (lesson 99) when there is only one app.
06Common misconceptions
"OAuth is a login protocol." It gives access. OpenID Connect adds the ID token.
"Logging out of one app logs me out of all apps." Each app has its own session, and the provider has one more.
07How to say it in the interview
Say it like this
I would use the authorization code flow with PKCE: the app gets a one-use code and swaps it for tokens, so a stolen code is useless. I add OpenID Connect for login and check the ID token's issuer, audience and expiry.
08Check your understanding
- Name the four roles in OAuth. What does OpenID Connect add?
- There are 3,000 staff and 6 apps. Without SSO each person logs in to each app once a day. With SSO, once a day in total. How many logins for each? How many fewer?
- A phone app keeps a client secret inside the app. What is wrong, and what do you use?
09Answers
Show the answers
- Resource owner, client, authorization server, resource server. OpenID Connect adds the ID token.
- Without SSO: 3,000 x 6 = 18,000. With SSO: 3,000. That is 15,000 fewer, 6 times fewer.
- Anyone can take a secret out of an app. Use PKCE, so the app needs no secret.
10Sources
- https://www.rfc-editor.org/rfc/rfc6749.html (opens in a new tab), https://www.rfc-editor.org/rfc/rfc7636.html (opens in a new tab), https://www.rfc-editor.org/rfc/rfc9700.html (opens in a new tab) (no implicit or password flow), https://openid.net/specs/openid-connect-core-1_0.html (opens in a new tab), https://docs.oasis-open.org/security/saml/Post2.0/sstc-saml-tech-overview-2.0.html (opens in a new tab) (checked 20 Oct 2026).
Try it now, no sign-up
Related lessons and practice
Ask the AI tutor about this lesson
The tutor has read this lesson. Ask in your own words, any time. Free account, 20 questions a day.
Reading never needs an account. The account is for the tutor, the quiz, your notes and your progress.