Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Public and confidential clients

The printer can run its OAuth 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 server 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 authorization endpoint and making the token 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 key 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

Browser JavaScript

<script>

// app code

</script>

Installed app

Delivered to the user's device

const clientSecret =

"EXAMPLE_ONLY";

// ...

Exposed

A shared secret packaged in every copy can be extracted.

Confidential client

Browser

The printer's website

Requests a page

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.

Client type depends on the deployment's ability to protect a client credential.

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 endpoint. With a client secret, the printer's backend sends its ID and secret in the request's Authorization header, encoded with the HTTP Basic scheme, the base64 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%2Fcallback

The 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 certificate 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 code 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 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_wW1gFWFOEjXk

When 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.

A developer puts the same client secret in every copy of the printer's phone app. Does that make the app a confidential client? 1 of 3

Choose one answer.

Someone copies an authorization code meant for the printer's phone app and sends it to the token endpoint with the app's client ID. The app used PKCE. What happens? 2 of 3

Choose one answer.

The printer's website runs its pages as JavaScript in Ava's browser, but its backend makes the token requests with a secret kept on its servers. Which kind of client is it? 3 of 3

Choose one answer.

Try it in the Lab

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.

  1. The Secret SPA Difficulty 1 of 5 · About 25 minutes · Browser application

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity