Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
The client credentials flow is the OAuth 2.0 grant for machine-to-machine access: an application authenticates as itself, with no user present, and receives an access token.

What Is the Client Credentials Flow?
Most OAuth 2.0 grants exist to get a user’s permission. The client credentials flow exists because sometimes there is no user. A nightly reconciliation job, a payments service calling a ledger service, a monitoring agent pulling metrics—none of these can show a consent screen to anyone, and none should be running under a staff member’s account.
The flow is the simplest in the specification. The client posts its own credentials to the token endpoint with grant_type=client_credentials, the authorisation server checks them, and an access token comes back. One request, one response, no redirects, no browser.
A request looks like this, with the client identifier and secret presented either in the body or using HTTP Basic authentication:
POST /oauth2/token HTTP/1.1
Host: login.example.co.uk
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials
&client_id=svc-reconciliation
&client_secret=REDACTED
&scope=ledger.read ledger.reconcile
The response carries an access token, a token type, and an expiry in seconds. There is no refresh token, and there should not be: the client already holds credentials that let it mint a new access token whenever it needs one. A refresh token would add a second long-lived secret for no benefit.
Critically, the token represents the application, not a person. Its subject claim is the client identifier. Any resource server that assumes sub is a human user will make incorrect authorisation decisions the first time a service account calls it, and that mistake has produced real privilege escalation in APIs that shared authorisation code between user and machine callers.
A client secret is a long-lived bearer credential, and it behaves exactly like a password that nobody rotates. Secrets end up in configuration files, in container images, in CI/CD variables, in a wiki page from 2022, and in public repositories. GitHub’s secret scanning programme detects millions of exposed credentials a year, and OAuth client secrets are a well-represented category.
Two better options exist, and both are widely supported:
Where a secret is unavoidable, remove it from your own storage entirely. Managed identities in Azure, IAM roles for service accounts in AWS and Google Cloud, and SPIFFE identities in Kubernetes all give a workload a credential it never has to hold on disk. Where you genuinely must hold one, it belongs in a vault with rotation, as covered in secrets management.
Machine clients suffer the same drift as human accounts, with less scrutiny. A service registered in 2021 to read invoices is granted write access for one migration and keeps it. Nobody reviews it, because reviews are aimed at people.
Register one client per workload rather than one per team, request the narrowest scopes that the job needs, and use the audience parameter so a token issued for the ledger API is rejected by the payments API. Keep access token lifetimes short—minutes, not hours—since the client can always request another. Include machine clients in your access review cycle with a named technical owner, and treat an unowned client as a candidate for disablement.
Three operational details separate a sound implementation from a fragile one. First, cache tokens. A client that requests a fresh token for every API call will hit rate limits on the authorisation server and generate log volume that hides real anomalies; request once, reuse until shortly before expiry. Second, handle rotation without downtime by supporting two active credentials at once, so you can introduce the new key before retiring the old one. Third, log and alert on client credential grants from unexpected source addresses, since a stolen secret used from a different network is one of the few detectable signals you get.
Finally, resist the temptation to use this flow for anything that does involve a user. If a person is present, use the authorisation code flow with PKCE; a machine token with broad scopes acting on behalf of users is a common and consequential design error.
At Privia Security, we test machine-to-machine authorisation and token handling in our web application security services.
Whenever a user is involved. If the request is made on someone’s behalf, use the authorisation code flow with PKCE so the token carries that person’s identity and permissions. Using client credentials in a user-facing application means every action is attributed to the application, you lose per-user authorisation, and the audit trail cannot tell you who did what.
Because the client already holds credentials that let it obtain a new access token at any time. A refresh token would be a second long-lived secret with no additional benefit and an additional theft surface. If your library expects one, the correct behaviour is to request a fresh access token from the token endpoint when the current one nears expiry.
Use platform workload identity where the cloud provider issues short-lived credentials that never touch your configuration: managed identities in Azure, IAM roles for service accounts in AWS or Google Cloud, or SPIFFE identities in Kubernetes. Where the authorisation server supports it, private key JWT or mutual TLS client authentication also removes the shared secret from the exchange entirely.
Only the ones the specific workload calls, and no more. Register a separate client per workload rather than one per team, set the audience so a token for one API is rejected by another, and keep lifetimes to a few minutes. Then review machine clients on the same schedule as privileged user accounts, with a named technical owner for each.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.