View a markdown version of this page

Obtain a token for your application with the client credentials grant - AWS Identity and Access Management

Obtain a token for your application with the client credentials grant

Note

This is prerelease documentation for a service in preview release. It is subject to change.

The client credentials grant lets your application or agent call an external service as itself. There is no end user and no consent. Use this flow when the work is not tied to a specific person, such as a background job or a shared integration. Credential Broker obtains the token, caches it, and refreshes it, so your application retrieves a token with a single call.

Key characteristics

The client credentials grant has the following characteristics:

  • No end user and no consent prompt

  • Your application authenticates as itself with its own credentials

  • Permissions are defined at the application level rather than per user

  • Credential Broker caches and refreshes the token for you

Example scenario

A reporting job that runs on Lambda reads shared account data from the company's Salesforce organization on a schedule, with no person signed in. The data belongs to the organization, not to a specific user. The job uses the client credentials grant so that it authenticates as itself.

  1. Priya (identity admin) creates a credential provider pool and a credential provider that allows the client credentials grant and that connects to the company's Salesforce app, and grants the job's role permission to call the broker.

  2. Diego (application developer) calls the broker from the job with the provider ARN and the scopes that the job needs. He writes no token handling and never sees the provider's client secret. Credential Broker returns a token that the job uses to call Salesforce.

How it works

At runtime, your application obtains a token in a single call.

To obtain a token with the client credentials grant
  1. Call GetOAuthToken with the client credentials grant, the provider ARN, and the scopes that you need. The response returns the access token and its expiration time.

  2. On later calls, Credential Broker returns the cached token until it expires, then obtains and caches a new one. Your application repeats the same call each time it needs a token.

Set up

Before you run this flow, configure the following:

  1. Create a credential provider pool.

  2. Create a credential provider that allows the client credentials grant and that is registered with your outbound identity provider. You reference this provider by its ARN, in the form arn:aws:credentialbroker:<region>:<account>:credentialproviderpool/<pool-id>/credentialprovider/<provider-id>.

  3. Grant the caller's role the credentialbroker: permissions for this flow. For more information, see Control access to AWS IAM Credential Broker.

For a worked example that configures a credential provider and retrieves a token, see Getting started: Set up your first credential provider.