Course contentsShow
← System Design
Lesson 925 of 1,91924. Authentication and Authorization at ScaleFree lesson

Client Credentials Flow

Machine-to-machine authentication using client ID and secret without user involvement.

Client Credentials Flow

What you'll learn: How machine-to-machine (M2M) authentication works in OAuth2 when no human user is involved.

The Machine-to-Machine Authentication Problem

When one service needs to call another service's API—for example, a billing service querying a payment processing service—there's no human user to log in. The services need to authenticate directly with each other. Client Credentials Flow solves this by allowing a service to authenticate using its own identity.

How It Works

Unlike Authorization Code Flow (which involves a user authorizing access), Client Credentials Flow is purely machine-to-machine:

  1. Your service (the "client") has been pre-registered with the authorization server and given two pieces of secret information: a client_id and a client_secret
  2. The client sends these credentials directly to the authorization server's token endpoint
  3. The authorization server validates the credentials and returns an access token
  4. The client uses this token to call the protected API

Think of it like a service account password: the client_id is the username, the client_secret is the password, and the access token is a temporary session key.

When to Use It

Use Client Credentials Flow when:

  • No user interaction is possible or needed
  • A service needs to access its own resources or call another service
  • Backend batch jobs, cron tasks, or microservices need API access

This flow is never appropriate for user-facing applications because the client_secret must remain confidential—and user devices (mobile apps, SPAs) cannot keep secrets.

Key Takeaway: Client Credentials Flow enables secure machine-to-machine authentication by exchanging a service's client ID and secret for short-lived access tokens, eliminating the need for user involvement.