---
title: "OAuth Client Credentials Flow"
description: "The OAuth Client Credentials Flow Explained."
url: "https://curity.io/resources/learn/oauth-client-credentials-flow/"
date: "2024-06-10"
area: "develop"
topic: "oauth"
keywords: "oauth client credentials flow, oauth client credentials flow overview, oauth client credentials flow benefits, oauth client credentials flow use cases, oauth client credentials flow scenarios, oauth client credentials flow considerations, oauth client credentials flow best practices, oauth client credentials flow recommendations, oauth client credentials flow security, oauth client credentials flow security benefits, oauth client credentials flow security considerations, oauth client credentials flow security best practices, oauth client credentials flow security recommendations"
---

# OAuth Client Credentials Flow

## What is a Client Credentials Flow in OAuth 2.0?

One of the flows specified in the OAuth 2.0 protocol is the Client Credentials flow. The Client Credentials flow is a server to server flow, where no user authentication is involved in the process. In fact there is no user at all, the resulting access tokens will not contain a user, but will instead contain the Client ID as subject (if not configured otherwise).

## When to Use the Client Credentials Flow

This flow is useful for systems that need to perform API operations when no user is present. It can be nightly operations, or other that involve contacting OAuth protected APIs.

### Client Credentials Flow vs Authorization Code Flow

The main difference between the Client Credentials flow and the [Authorization Code flow](https://curity.io/resources/learn/oauth-code-flow/) is that the Client Credentials flow relies on application authorization rather than involving the user. Since there is no user authorization, the flow only interacts with the token endpoint.

### Steps in the Client Credentials Flow

### Token Endpoint

![Illustration with the steps in the client credentials flow](https://curity.io/images/resources/standards/oauth/flows/cc-flow-01.svg?v=20210408) 

1.  The Client makes a POST request to the OAuth Server
2.  The OAuth Server issues the Access Token immediately and responds to the client

### Benefit of Using the Client Credentials Flow

The benefit of using the OAuth 2.0 Client Credentials flow in contrast to merely [basic authentication using API keys](https://nordicapis.com/keep-api-keys-safe-because-the-repercussions-are-huge/) is two-fold. Firstly your API infrastructure can be made uniform, no matter if the request comes from an authenticated user or from a server with a system user, the authentication in the API can be reused.

Secondly when [using client credentials](https://curity.io/resources/learn/client-credentials/) you limit the parties that you send the credentials to. In OAuth the client calls the [token endpoint](https://www.rfc-editor.org/rfc/rfc6749#section-4.4) to retrieve an access token and then uses that token to call the API. Using basic authentication such as API keys only, would mean that the client would send the credentials to any API it needs to communicate with, thus more parties share the secret.

### Client Authentication

The client authenticates as part of the token request. There are many ways for a client to authenticate. The most common being client secret. The Curity Identity Server supports the following authentication mechanisms for clients:

-   No authentication (public client)
-   Secret in POST body
-   Secret using Basic Authentication
-   Client Assertion JWT
-   Mutual TLS (mTLS) client certificate
-   Asymmetric Key
-   Symmetric Key
-   Credential Manager
-   JWKS URI

### The Access Token

The access token is returned by the token endpoint. It is the token that clients can use to call the API and gain access. It is often a bearer token, and as such, the client must not send it to untrusted parties. The access token usually has a lifetime of 5-30 minutes.

### The Refresh Token

No refresh token is issued. The client can make the same call again to obtain a new access token.

## The Token Endpoint

### Request Parameters

-   Method: `POST`
-   Content-Type: `application/x-www-form-urlencoded`
-   Response Type: `json`

| Parameter | Value | Mandatory | Description |
| --- | --- | --- | --- |
| client\_id | The Client ID | yes | The ID of the requesting client |
| client\_secret | The client secret | yes\* | The secret of the client. \*Mandatory if client authentication is of type secret, and the authentication is not done using basic authentication |
| grant\_type | `client_credentials` | yes | Tells the token endpoint to perform the Client Credentials flow. |
| scope | Space separated string of scopes | no | List the scopes the client is requesting access to. |

### Response

-   Response Type: `application/json`

| Parameter | Value | Mandatory | Description |
| --- | --- | --- | --- |
| access\_token | A newly issued access token | yes | The resulting access token for the flow |
| expires\_in | Expiration in seconds | yes | The time to live of the access token in seconds |
| scope | Space separated string | no | If not present the requested scopes were issued. If present the issued scopes may differ from the requested scopes. |
| token\_type | `Bearer` or other token type | yes | Describes how the token can be used. Most commonly bearer token usage. |

## Conclusion

There are various flows and grant types in OAuth 2.0. For server to server communications, use the Client Credentials flow. When a user is present, you should use the Authorization Code flow instead, so that your APIs always receive the user identity securely, in the access token.
