Public and confidential clients
The printer can run its OAuthA framework that lets a person give an application limited access to their resources at another service, using tokens instead of sharing their password. OAuth is about access; OpenID Connect adds sign-in. work on the printing company's own servers or inside an app on each customer's phone. Where it runs decides whether it can keep a credential to itself, and that decides how the authorization serverIn OAuth, the service that handles a person's sign-in and approval and decides which tokens to issue to a client. It may belong to the same company as the API, but its job is separate. can tell the real printer from a copy.
Where the client runs
So far the printer has been one participant. In practice its OAuth responsibilities, sending Ava's browser to the authorizationDeciding whether a requested action is permitted, such as whether a signed-in account may delete a particular photo. Authentication says which account is asking; authorization decides what it can do. endpoint and making the tokenA piece of data issued by a trusted service that a client presents as a credential, for example to call an API or to report a sign-in. Some tokens carry readable claims; others are random strings that only the issuer can interpret. request, could run in different places. The printer's website could do them on its backend, the part that runs on the printing company's own servers. A version written entirely as JavaScript could do them in Ava's browser. And the printer's phone app, installed on each customer's own phone, could do them on the phone.
Where the client runs affects the credentials it can protect. A confidential client can protect a credential it uses to authenticate itself to the authorization server. The printer's backend can keep a client secret, a long random value the authorization server issued to it, or a private keyThe half of a key pair that its owner keeps to themselves and uses to create signatures or decrypt data. Anyone who obtains it can act as its owner. from Secrets and key pairs, on servers the printing company operates, outside any code or file sent to a customer.
A public client cannot rely on keeping a credential confidential in the place it runs. JavaScript delivered to a browser can be read by anyone running it, with the browser's own developer tools, so a secret written into it is available to every visitor. The phone app has the same problem in another form: the same secret packaged into every copy can be pulled out of any one copy. An installed app does not become confidential because a developer hid a secret in its package, however carefully.
The words "public" and "confidential" describe only this ability to protect a credential. They do not say whether the application is publicly available, whether its source code is open, or whether its users need accounts. The printer's website is open to everyone and can still be a confidential client, because its backend makes the token requests.
Public client
<script>
// app code
</script>
Delivered to the user's device
const clientSecret =
"EXAMPLE_ONLY";
// ...
A shared secret packaged in every copy can be extracted.
Confidential client
The printer's website
Company backend (operated environment)
Client credential (secret or private key)
Credential stays on the operated backend
The client can authenticate with a secret or private key.
client_idBoth can have a client ID. A client ID is not proof of identity.
Public and confidential describe credential protection, not who can use the app.
Identifying and authenticating clients
Both kinds of client have a client ID, the identifier the authorization server gave the client when it was registered, such as photo-printer. It tells the server which registration, with which redirect URIs and allowed scopes, a request is about. It is not a secret: it appears in the authorization request that passes through Ava's browser, so anyone can read it and anyone can send it. Knowing a client ID is no proof that a request came from the legitimate application.
A confidential client can add that proof through client authentication at the token endpointThe authorization server address where clients exchange an authorization code, refresh token, or other grant for tokens, in a direct request rather than through a browser redirect.. With a client secret, the printer's backend sends its ID and secret in the request's Authorization header, encoded with the HTTPThe Hypertext Transfer Protocol, the rules browsers, apps, and servers use to send requests and responses on the web. Basic scheme, the base64A way of encoding data as ordinary text characters so it can travel safely in headers, URLs, and JSON. Anyone can decode it, so it hides nothing; Base64url is a variant safe for URLs, used in JWTs. from Encoding and hashing:
POST /token HTTP/1.1
Host: auth.photos.example
Authorization: Basic cGhvdG8tcHJpbnRlcjpFWEFNUExFX09OTFk=
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code&code=SplxlOBeZQQYbYS6WxSbIA&redirect_uri=https%3A%2F%2Fprinter.example%2Foauth%2FcallbackThe header value decodes to photo-printer:EXAMPLE_ONLY, an example ID and secret. Instead of a shared secret, a client can also prove itself with a private key, by signing a short statement for the token endpoint, or with a certificateA signed statement that a public key belongs to a name, such as a website's hostname, for stated purposes and a limited period. A certificate authority signs it, so software that trusts the authority can connect the key to the name. on the connection itself. Either way, the authorization server now knows the token request came from the printer, not just a request naming it, and its records can name the printer as the actor.
A public client has nothing equivalent. It sends only its client ID, and hiding a shared secret more carefully in downloadable code cannot change that. It needs protection designed for its situation, which the next section describes.
Protecting the code exchange
Without client authentication, anyone who gets hold of an authorization codeA short-lived, single-use value that the authorization server sends back to a client through the browser. The client swaps it for tokens in a direct request to the authorization server; APIs never accept it. meant for the phone app could try to redeem it at the token endpoint, sending the app's public client ID with it. Proof Key for Code Exchange, usually called PKCE and pronounced "pixie", closes that gap.
For each authorization attempt, the app creates a fresh random secret, the code verifier, and keeps it on the phone. It sends a value derived from it, the code challenge, in the authorization request: the verifier's SHA-256 hashTurning data into a short, fixed-size value called a hash, in a way that cannot be reversed and where changing one character changes the result completely. Services store password hashes instead of passwords, and signatures are made over a hash., base64url-encoded, with code_challenge_method=S256 to say which method made it.
Authorization request (through the browser):
code_challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
code_challenge_method=S256
Token request (directly to the token endpoint):
grant_type=authorization_code
code=SplxlOBeZQQYbYS6WxSbIA
client_id=photo-printer-app
code_verifier=dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXkWhen the app redeems the code, it sends the original verifier. The authorization server hashes it the same way and compares the result with the challenge it stored with the code. Only the app instance that started the attempt holds the verifier, and a hash cannot be reversed to find it, so someone who obtained the code from the browser's journey, without the verifier, cannot redeem it. The token request fails.
PKCE does not identify the application the way a confidential client's credential does. A copied phone app can still start its own attempt with its own verifier; PKCE only ties each code to the attempt that asked for it. An attempt-specific secret and a credential that identifies a registered client do different jobs, so confidential clients use PKCE as well, alongside their client authentication, and current guidance recommends it for every client.
A product can also contain parts with different responsibilities. The printer's website might use its backend as a confidential client while Ava's browser talks to that backend through an ordinary session cookie from Staying signed in. Calling the whole product "a web app" does not say where the OAuth credentials live. Before choosing a flow, identify which component acts as the client, where it runs and which credentials it can protect.
Check your understanding
Try these questions before moving on. If an answer isn't right, use the feedback and try again.
Try it in the Lab
- Register the printer twice, as a confidential and a public clientCreate lab-printer and lab-printer-app, give only the confidential one a secret, and compare how the tenant treats a public client's requests.
Try a Capture the Flag challenge
Apply this lesson against an isolated, intentionally vulnerable application. Capture a flag, explain the mistake, then repair and retest it.