

# AWS IAM Credential Broker

AWS IAM Credential Broker obtains, refreshes, and vaults the credentials that an agent or workload on AWS needs to call systems outside AWS. These credentials include OAuth access tokens for SaaS applications, external identity providers, and internal APIs outside AWS, data-platform tokens, and static API keys. Your agent presents its own AWS IAM credentials, and Credential Broker returns a third-party credential that it obtained on behalf of the agent or the user from an OAuth provider. The agent receives a short-lived access token and doesn't handle the authorization server's client secret. From an API key provider, it receives the API key, which Credential Broker stores and governs centrally rather than leaving it in your agent's configuration.

Your developers don't need to build OAuth logic into their agents and applications. Credential Broker takes on the undifferentiated OAuth plumbing, such as consent, code exchange, token storage, and refresh, and simplifies connecting your agents to external applications.

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

Credential Broker doesn't issue credentials. Your identity provider, the external authorization server, or the SaaS platform issues every token. Credential Broker obtains those tokens on your behalf, caches them, and returns them to your agent.

**Note**  
If your external service can accept a JSON Web Token (JWT) issued by AWS, use IAM [Getting started with outbound identity federation](id_roles_providers_outbound_getting_started.md) instead. With outbound federation, AWS issues the token and there's no client secret to store.

You can use Credential Broker from any AWS compute, including Lambda, Amazon ECS, Amazon EKS, Amazon EC2, and agents that run on AWS.

**Note**  
Building agents on Amazon Bedrock AgentCore? Keep using AgentCore Identity, including its credential providers and token vault, to give your AgentCore agents access to external services. AWS IAM Credential Broker is for workloads on other AWS compute, such as AWS Lambda, Amazon ECS, Amazon EKS, and Amazon EC2, that need to call services outside AWS.

With Credential Broker, you can do the following:

**Centralize client secrets and API keys.**  
Credential Broker holds client secrets and API keys in AWS Secrets Manager, instead of spreading them across your compute.

**Keep tokens current without building the OAuth flow.**  
Credential Broker obtains tokens and keeps them current, so your agent does not implement consent, code exchange, or refresh itself. For flows that act for a user, it refreshes the token silently; for the client credentials grant, it obtains a new token.

**Return a user's credential only for that user.**  
For flows that act for a user, Credential Broker returns a user's credential only to requests made on that user's behalf, by an IAM principal that has permission to use the credential provider.

**Encrypt cached credentials with your choice of key.**  
Credential Broker encrypts cached credentials at rest with an AWS owned key by default, or with a customer managed key that you choose.

**Retrieve credentials at run time.**  
Your agent retrieves credentials when it needs them, instead of keeping them in its code, configuration, or environment variables.

## How AWS IAM Credential Broker works
<a name="credential-broker-how-it-works"></a>

Credential Broker works in two phases: a one-time setup, and retrieval of credentials at run time.

**Setup (you do this once)**

1. Create a credential provider and configure it for the type of credential your agent needs. For an OAuth provider, this includes the provider's endpoint or domain, the client credentials of your app registration, and, for flows that act for a user, the allowed session binding URLs. For an API key provider, it's the API key. Credential Broker keeps client secrets and API keys in AWS Secrets Manager, so they stay out of your agent.

1. Optionally, choose a customer managed key to encrypt cached credentials, on the pool or on an OAuth provider. By default, Credential Broker uses an AWS owned key.

**At run time**

1. Your agent calls Credential Broker with its own AWS IAM credentials, signed with SigV4 under its IAM role.

1. When the agent acts for a user, its IAM role session must also carry that user's identity. You can add the user context with trusted identity propagation, either [trusted identity propagation for IAM](https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_tip_federation_configure.html) or [trusted identity propagation for IAM Identity Center](https://docs.aws.amazon.com/singlesignon/latest/userguide/trustedidentitypropagation-overview.html). Credential Broker reads that context and derives a stable end-user identity. It doesn't authenticate the end user itself.

   The same user-aware credentials that your agent uses to access AWS resources on the user's behalf can be used to retrieve OAuth tokens from Credential Broker.

1. Credential Broker checks that the caller has IAM permission to use the credential provider and, for flows that act for a user, that the request is made on behalf of the user the credential was obtained for.

1. To obtain the credential, Credential Broker calls the external identity provider or authorization server with the client credentials it holds in AWS Secrets Manager. Credential Broker then caches the credential, encrypted at rest.

1. Credential Broker caches a token for up to one hour, or until it expires if sooner. For flows that act for a user, Credential Broker refreshes the token silently from the stored refresh token, without prompting the user again. For the client credentials grant, there is no refresh token; Credential Broker obtains a new token.

## Credential Broker resources
<a name="credential-broker-resources"></a>

Credential Broker provides the following resources:

Credential provider  
A credential provider obtains credentials from an external identity provider and authorization server on behalf of your agents and workloads.

Credential provider pool  
A credential provider pool groups credential providers and holds the settings that they share.

## What type of credential do you need?
<a name="credential-broker-choose-credential"></a>

A credential provider holds one type of credential, and its type is fixed when you create the provider. Choose the type that your external service accepts:

**API key**  
Choose an API key provider for an external service that authenticates with a static API key. The provider holds one API key, and your agent retrieves it with the `GetApiKey` operation. The caller's IAM policy must allow the `credentialbroker:GetApiKey` action on the provider's ARN.

**OAuth token**  
Choose an OAuth token provider for an external service that accepts OAuth access tokens. Then select the token provider, the identity provider or SaaS platform that issues the tokens. To get started quickly, choose one of the provider templates, which account for each vendor's OAuth requirements, or choose a custom configuration. Your agent retrieves a token with the `GetOAuthToken` operation. To choose a flow for an OAuth token provider, see the following section.

### Choosing a flow
<a name="credential-broker-grant-types"></a>

An OAuth token provider obtains tokens with one of three flows: the client credentials grant (M2M), the authorization code grant (3LO), or the token exchange grant (OBO). The following table compares the flows across the factors that determine which one fits your use case. For details about each flow, see [Obtain a token for your application with the client credentials grant](credential-broker-m2m.md), [Obtain a token on behalf of a user with the authorization code grant](credential-broker-3lo.md), and [Obtain a token with the token exchange grant](credential-broker-obo.md).


**OAuth flow comparison**  

| **Factor** | **Client credentials grant (M2M)** | **Authorization code grant (3LO)** | **Token exchange grant (OBO)** | 
| --- | --- | --- | --- | 
| Data ownership | Data owned by the application or organization, not a specific user. | User-specific data, accessed with that user's explicit consent. | User-specific data, for a user whose identity is already established, through IAM Identity Center or an earlier consent. | 
| User interaction | None. There is no end user. | The user is present and approves access once in a browser. | The user is already signed in. No new consent prompt appears. | 
| Operation timing | Background, scheduled, or batch work. | Interactive, with a one-time consent step before the first token. | No prompt for the user. Works wherever the caller's session carries the user's identity and a subject token exists for that user. | 
| Permission scope | Permissions are fixed at the application level. | Permissions follow the scopes the user consented to. | Permissions derive from the signed-in user's identity and the provider configuration. | 

## Related resources
<a name="credential-broker-related"></a>
+ [Credential Broker API Reference](https://docs.aws.amazon.com/credentialbroker/latest/APIReference/)
+ [AWS CLI commands for Credential Broker](https://docs.aws.amazon.com/cli/latest/reference/credentialbroker/)