Beta

Create a tenant

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

Client credentials

Some requests have no person behind them at all: a scheduled job sends work to a partner's API on its own account. The client credentials grant gives a confidential client an access token that represents the client itself, which makes that client's credential, and the access it unlocks, worth keeping small.

A client acting for itself

Every evening, the printer sends the day's finished photo books to the print lab, the business that prints them. The print lab runs an API that accepts print jobs from partner applications. Nobody is at a browser when this happens: a scheduled job on the printer's backend collects the orders and submits them.

Every request so far carried access that Ava delegated. The printer read her photos because she approved it, and even the December refresh only carried that approval forward. Here there is no photo account and no one to ask. The printer needs access to the print lab's API as itself.

The client credentials grant covers this situation. The client authenticates to the authorization server with its own credentials and receives an access token that represents the client, not a user.

That changes what the API is deciding. In the authorization code flow, the photo API asked whether the printer could read Ava's photos, and the answer rested on her approval. Here, the print lab's API asks whether the printer, as a registered partner, may submit print jobs. The answer depends on what the print lab has allowed that partner to do, not on any person's approval.

Reading Ava's photos

Who authenticates
Ava, then the printer
Who approves
Ava
Token represents
The printer acting for Ava
API decides from
Ava's approval

Photo API reads her album

Submitting print jobs

Who authenticates
The printer only
Who approves
No person
Token represents
The printer itself
API decides from
What the print lab allowed

Print lab API takes the job

A browser app tries

Who authenticates
Nothing it can protect
Who approves
No person
Token represents
No token issued
API decides from
Nothing to decide

Refused at the token endpoint

Anyone holding the printer's secret can get tokens for everything the printer is allowed to do.

The same printer holds two kinds of token. One carries Ava's approval; the other represents the printer alone. A browser app that can't protect a credential gets no token of its own this way.

Because the client proves who it is with its own credentials, this grant is only for confidential clients. The print lab has registered the printer's order service as a client, and the printer keeps that client's secret on the backend that runs the scheduled job. An application running in Ava's browser or installed on her phone is a public client: it has no credential of its own that it can protect, so it can't use this grant to act as itself.

Requesting a token

The printer's backend sends a direct request to the print lab's token endpoint. As in the code exchange, this example uses HTTP Basic client authentication: the header carries the base64 encoding of printer-orders:demo-only-not-a-real-secret, the client ID and secret joined by a colon.

POST /token HTTP/1.1
Host: auth.printlab.example
Authorization: Basic cHJpbnRlci1vcmRlcnM6ZGVtby1vbmx5LW5vdC1hLXJlYWwtc2VjcmV0
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials
&scope=print-jobs.write

All domains, credentials and tokens in these examples are fictional.

Compare this with the authorization code exchange. There is no code, no redirect URI and no PKCE verifier, because there was no earlier browser visit to connect to. The client's authentication is the whole basis of the request.

The authorization server checks those credentials, confirms that this client is allowed to use the grant, and decides which of the requested scopes to issue. A successful response looks familiar:

HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: no-store
Pragma: no-cache

{
  "access_token": "demo-lab-access-token-2",
  "token_type": "Bearer",
  "expires_in": 900,
  "scope": "print-jobs.write"
}

There is no refresh token, and RFC 6749, the OAuth 2.0 specification, says there shouldn't be one for this grant. The yearly calendar needed a refresh token because Ava wouldn't be there in December to approve access again. The order service has a different basis for access: it can authenticate as itself whenever it needs a new token, so a refresh token would only add a second long-lived credential that does nothing the client secret can't already do. The fifteen-minute lifetime is this example's choice, not a rule every service follows.

The printer authenticates as itself and receives a token that represents the printer. The print lab API decides what that partner may do.

Keeping the access narrow

The printer now submits jobs with the token:

POST /print-jobs HTTP/1.1
Host: api.printlab.example
Authorization: Bearer demo-lab-access-token-2
Content-Type: application/json

{ "order": "book-5561", "product": "hardcover-a4" }

A sensible client keeps the token until shortly before it expires and uses it for the whole evening's batch, rather than requesting a new token for every job. When a request is refused because the token has expired, it requests another one.

The print lab still decides which operations the printer may perform. A token issued to the printer doesn't prove that a particular customer approved a particular order. If that proof matters, it has to come from the printer's own order records and checks, not from a customer name added to the request body, which the printer could write for anyone.

That makes the client's credential especially valuable. Anyone holding the printer's secret can get tokens for everything the printer is allowed to do, at any time, with no person in the loop to notice or refuse. So the print lab grants the printer only the scopes its job needs, a token request that asks for anything else is refused, and the printer keeps its secret out of source code, logs and shared configuration. Secrets and signed assertions looks at a stronger way for a client to authenticate, and Rotating client credentials at how to replace a credential without interrupting the service that depends on it.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

The print lab API receives a job submitted with a token from the client credentials grant. What does the token tell it? 1 of 3

Choose one answer.

A photo editing app runs entirely as JavaScript in the browser. Can it use the client credentials grant to call an API as itself? 2 of 3

Choose one answer.

The printer's order service only submits print jobs. Its developer asks the print lab to also grant it photo reading, just in case. Why should the print lab refuse? 3 of 3

Choose one answer.

Try it in the Lab

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