OAuth2 Client Credentials Flow
The OAuth2 Client Credentials Flow is the grant type designed for machine-to-machine (M2M) communication — situations where there is no human user involved and a service must authenticate as itself to call another service's API.
The OAuth2 Client Credentials Flow is the grant type designed for machine-to-machine (M2M) communication — situations where there is no human user involved and a service must authenticate as itself to call another service's API.
Unlike the OAuth2 Authorization Code Flow, there is no browser redirect, no user login screen, and no consent prompt. The flow is entirely back-channel: the client service holds a client_id and client_secret (or a signed JWT assertion) and exchanges them directly for an access token.
The requesting service sends a POST to the authorization server's /token endpoint with grant_type=client_credentials, its credentials, and the scope of access required. The authorization server validates the credentials against its client registry, checks that the requested scopes are permitted for this client, and returns an access token — typically a short-lived JWT (15 minutes to 1 hour is common).
The service then attaches this access token as a Bearer header on outbound API calls to the resource server. The resource server validates the token's signature, expiry, and scope claims before processing the request. When the token expires, the service requests a new one; there is no refresh token in this flow because the client can always re-authenticate immediately using its credentials.
Token caching is critical for performance at scale: fetching a new token for every API call adds latency and load to the authorization server. A well-implemented client caches the token and proactively renews it shortly before expiry (typically at 80–90% of its lifetime).
The Client Credentials Flow is the backbone of microservice-to-microservice auth in platforms like Auth0, Okta, and Azure AD. For APIs that use simpler long-lived secrets rather than short-lived tokens, compare API Key Authentication. Token structure and validation are covered in JWT Authentication Flow.