Skip to content

Interview PrepOAuth & OIDC · Core

OAuth 2.0 Basics ​

71. What is OAuth 2.0, and what problem does it solve? ​

The short answer

OAuth 2.0 is a standard way for a user to let one application access their data in another service without giving it their password. Before OAuth, a budgeting app that wanted your bank transactions would ask for your bank password, then hold full access forever. With OAuth, the app sends you to the bank, you log in at the bank and approve "read transactions only", and the bank gives the app an access token limited to that permission, which you can revoke at any time. The app never sees your password.

The valet key is the classic picture. Some cars come with a valet key. It starts the engine and opens the door, but not the boot or the glovebox, and it may limit the speed. You hand the valet that key, not your main key. OAuth tokens are valet keys for your data: limited, temporary, revocable.

Before OAuthWith OAuth
App asks for your passwordApp never sees your password
App gets full accessApp gets only the scopes you approved
Revoking means changing your password everywhereRevoke one app's token in your account settings
Bank cannot tell apps apartBank knows which app is calling and logs it

Where you have used it. "Allow this app to see your Google Calendar". "Connect your GitHub account to this CI service". "Let this printing site use your Dropbox photos". Each is an OAuth consent screen.

72. Is OAuth 2.0 an authentication protocol or an authorization framework? ​

The short answer

OAuth 2.0 is an authorization framework. An access token says "the holder may do these things", not "this is user Asha, who just logged in". The token may not identify the user at all, may not be meant for the client to read, and could have been issued hours ago. Using a bare OAuth access token as proof of login has caused real account-takeover bugs. OpenID Connect is the layer on top that adds authentication, with an ID token that is specifically about who logged in, when, and for which app.

Why a plain access token is not proof of identity:

  1. It may be for someone else's app. An attacker's own app receives a user's token, then sends it to your app's "log in with this token" endpoint. If you only ask the provider "is this token valid?", you log the attacker in as the user. The token was valid, just not issued to you.
  2. It does not say when the user logged in, or whether they did at all; refresh tokens can create access tokens with no user present.
  3. Its format is not standard. It might be opaque. Its claims, if any, are up to the provider.

An ID token fixes each one: aud is your client ID, auth_time says when the user logged in, and its format is standard (the ID token question).

73. How does authentication differ from delegated authorization? ​

The short answer

Authentication is the user proving who they are to an application. Delegated authorization is the user allowing an application to act on their behalf at another service, within limits. In authentication, the app learns "this is Asha". In delegated authorization, the app gets "permission to read Asha's calendar", and may never learn who Asha is. OAuth handles delegated authorization. OpenID Connect handles authentication. "Sign in with Google" uses OIDC; "let this app manage your Google Drive files" uses OAuth; many logins request both at once.

AuthenticationDelegated authorization
QuestionWho is this user?What may this app do for the user?
ResultID token, or a sessionAccess token with scopes
Who uses the resultThe app itselfThe app, to call another service's API
StandardOpenID Connect, SAMLOAuth 2.0
ExampleSign in to Trello with GoogleTrello attaches files from your Google Drive

74. What are the main actors in OAuth 2.0? ​

The short answer

There are four. The resource owner is the user who owns the data and gives permission. The client is the application that wants access, such as a budgeting app. The authorization server authenticates the user, asks for consent and issues tokens, such as Google's or your bank's login service. The resource server is the API that holds the data and accepts the tokens, such as the bank's transactions API. The authorization server and resource server are often run by the same company, but they are separate roles.

resource ownerAshaclientbudgeting appauthorization serverbank login + consentresource serverbank transactions APIuseslogs in and approves "read transactions"access tokenGET /transactions · Bearer token
Four roles, one permission. The user approves at the authorization server, never inside the client. The client receives only a token, and uses it at the resource server. The password stays between the user and the bank.

75. What are the Resource Owner, Client, Authorization Server, and Resource Server? ​

The short answer

The resource owner is whoever can grant access to the data, usually the end user. The client is the app requesting access; it is identified by a client_id and, if it can keep a secret, a client_secret. The authorization server issues tokens after authenticating the owner and getting consent; it exposes /authorize and /token endpoints. The resource server hosts the protected API and validates each token's signature, expiry, audience and scopes before serving data. In the client credentials flow, the client is also its own resource owner.

RoleHoldsMust check
Resource ownerTheir login credentialsThat they trust the client asking
Clientclient_id, maybe client_secret, the tokensstate, PKCE, the ID token if using OIDC
Authorization serverUser accounts, client registrations, signing keysRedirect URI exactly matches; PKCE; client authentication
Resource serverPublic keys or an introspection endpointToken signature, exp, aud is itself, scopes allow the action

The bug resource servers make most often: checking the signature but not aud and scopes. A token issued for the read-only reporting API should not be able to call the payments API (the standard claims question).

76. What is an authorization grant? ​

The short answer

An authorization grant is the proof a client presents to the authorization server's token endpoint to get an access token. Different situations use different grant types. The authorization code grant, with PKCE, is for apps acting for a user. Client credentials is for a service acting for itself. Refresh token renews access. Device code is for TVs and command-line tools. Token exchange swaps one token for another. The old implicit and password grants are deprecated. Each grant is a different answer to "how do we know this client should get a token?".

GrantProof presentedUse for
Authorization code + PKCEA one-time code plus the PKCE verifierWeb, mobile and single-page apps with a user
Client credentialsThe client's own credentialsService to service, no user
Refresh tokenA refresh tokenRenewing access silently
Device authorizationA device code the user approved on a phoneTVs, CLIs, devices without a browser
Token exchangeAn existing tokenSwapping a user token for a narrower one (token exchange)
Implicit, passwordDeprecated, do not use (question 87)

77. What is an access token, and what is a refresh token in OAuth? ​

The short answer

In OAuth, the access token is the credential the client sends to the resource server to call the API, scoped to the permissions the user granted and valid for a short time. The client should treat it as an opaque string, even if it happens to be a JWT, because it is meant for the API, not the client. The refresh token lets the client get new access tokens from the authorization server without asking the user again. It is long-lived, must be kept secret, and is sent only to the token endpoint.

A token response from the token endpoint:

json
{
  "access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjIwMjYtMTAifQ…",
  "token_type": "Bearer",
  "expires_in": 900,
  "refresh_token": "8xLOxBtZp8",
  "scope": "transactions:read"
}

Reading it: expires_in is in seconds, here 15 minutes. scope shows what was actually granted, which may be less than requested, because the user can untick boxes. token_type: Bearer means "whoever holds this can use it", which is why it must be protected like a password. The lifecycle details are on the token lifecycle page.

78. What are OAuth scopes? ​

The short answer

Scopes are named permissions a client asks for, such as calendar.read, repo or orders:write. The user sees them on the consent screen and approves some or all. The issued access token carries the granted scopes, and the resource server checks that the scope needed for each endpoint is present. Scopes limit what the app may do on the user's behalf; they do not replace the API's own checks on what the user may do. Request the fewest scopes you need, at the moment you need them.

ts
export const requireScope = (scope: string) => (req: Request, res: Response, next: NextFunction) => {
  const granted = String(req.auth?.scope ?? '').split(' ')                       // (1)
  if (!granted.includes(scope)) return next(new HttpError(403, `Missing scope ${scope}`))   // (2)
  next()
}

router.get('/orders', requireScope('orders:read'), listOrders)
router.post('/orders', requireScope('orders:write'), createOrder)
  1. Scopes arrive as one space-separated string in the scope claim.
  2. No scope, no access, with 403, even if the user themselves could do it.

Scopes and user permissions work together. A support agent's token with orders:read lets the support app read orders. The API still checks whether this agent may see this customer's orders. A scope can only narrow what the user could already do, never widen it.

Scope design ruleExample
Resource and actionorders:read, orders:write
Coarse enough to understand on a consent screenNot orders.line_items.price:read
Ask lateAsk for contacts:read only when the user clicks "invite friends"
OIDC reserved scopesopenid, profile, email, offline_access

79. What is an OAuth consent screen? ​

The short answer

The consent screen is the page the authorization server shows after login, saying "Budget Buddy wants to: view your transactions, view your account balance. Allow or Deny?". It makes the user's permission explicit, shows exactly which app is asking and what it will get, and lets the user refuse or untick scopes. It is shown by the authorization server, never by the client, so a malicious app cannot fake or hide it. Enterprises often pre-approve trusted apps, so employees skip the screen.

What a good consent screen shows:

  1. The app's verified name and logo, and who publishes it.
  2. Each permission in plain words, with risky ones highlighted.
  3. The user's own account, so they know which one they are granting from.
  4. Links to the app's privacy policy and terms.
  5. Where to revoke access later.

Consent phishing. Attackers register an app called "Microsoft Security Update", and send a link to its consent screen. Users see a real Microsoft login page, sign in, and grant the attacker's app access to their mail. No password is stolen, so MFA does not help. Defences: only allow verified publishers, require admin approval for risky scopes, and review granted apps regularly.

80. What is the difference between public and confidential OAuth clients? ​

The short answer

A confidential client runs on a server you control, so it can keep a secret, such as a client_secret or a private key, and authenticate itself to the token endpoint. A traditional web back end is confidential. A public client runs on the user's device, such as a single-page app, a mobile app or a CLI. Anything shipped to a user's device can be extracted, so it cannot keep a secret. Public clients therefore must use PKCE, get shorter-lived or sender-bound tokens, and register exact redirect URIs.

Confidential clientPublic client
Runs onYour serverUser's browser, phone or laptop
Can keep a secretYesNo, it can be extracted
Authenticates to the token endpointclient_secret, or better, a signed JWT or mTLSOnly client_id
Required protectionPKCE recommendedPKCE required
Refresh tokensNormalRotated, or bound to the device
ExampleNext.js or Express back endReact app with no back end, iOS app

A mobile app with a "secret" is still public. Anyone can unpack the app and read a client_secret from it in minutes. Treat it as public and use PKCE.

Turning a public client into a confidential one. Add a small back end for front end that holds the secret and the tokens, and give the browser only a session cookie (the token storage question). This is the approach current OAuth guidance recommends for browser apps that handle sensitive data.

Combine chapters into one PDF

Pick the chapters you want. They print in the order you pick them.

Interview Prep
Authentication & Identity
Cookies & sessions
Authentication
Tokens
OAuth & OIDC
Enterprise SSO
Directories
Authorization
Other topics
Nothing picked yet