The client_credentials grant is the OAuth 2.0 flow for machine-to-machine access. A backend service authenticates as itself, using its client ID and secret (or a stronger credential), and receives an access token, with no user involved. It is defined in RFC 6749 section 4.4 and is the standard way for one service to call another service's protected API.
Because no user is present, the token represents the application, not a person, and it carries the permissions granted to that client.
Use it when the client is the resource owner or acts on its own behalf:
Do not use it in browsers, mobile apps or any public client that cannot keep a secret. When a user is involved, use the authorization code flow with PKCE instead. The implicit and resource owner password grants are removed in OAuth 2.1 and should not be used.
grant_type=client_credentials.Authorization: Bearer <token>.There is no refresh token in this flow. When the access token expires, the client simply requests a new one.
Then use the token against the API:
The -u option sends the client ID and secret in the Authorization header (the client_secret_basic method). Some servers also accept them as form parameters, but Basic is preferred.
Spring Security can obtain and cache tokens for you. Register the client in application.yml:
Then attach tokens to outgoing requests with a WebClient:
Spring requests a token on first use, caches it and renews it before it expires.
private_key_jwt or mutual TLS (RFC 8705).aud, iss, exp and scope claims in the resource server.No. RFC 6749 says a refresh token should not be included. Request a new access token when the old one expires.
No. The subject is the client itself. If you need to act for a user, use the authorization code flow or token exchange (RFC 8693).
No. A browser cannot keep a client secret, so anyone could extract it. Use authorization code with PKCE.
An API key is a static secret. Client credentials produce short-lived, scoped tokens that the server can verify and revoke, which is safer and auditable.
The client_credentials grant lets a trusted backend authenticate as itself and get a short-lived, scoped access token. Use it for service-to-service calls, protect secrets (or use mutual TLS or signed JWTs), keep scopes narrow, cache tokens, and choose the authorization code flow with PKCE whenever a user is involved.