# OAuth2CredentialProvider

L2 construct · Stable

L2 construct for `AWS::BedrockAgentCore::OAuth2CredentialProvider`.

Prefer the static factories (for example {@link OAuth2CredentialProvider.usingSlack}) so you only pass
the OAuth2 settings that apply to that vendor. To attach the identity to a gateway target, use
{@link GatewayCredentialProvider.fromOauthIdentity } with this construct, or
{@link OAuth2CredentialProvider.bindForGatewayOAuthTarget} with {@link GatewayCredentialProvider.fromOauthIdentityArn }.

Extends: [Construct](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Construct.html) › [Resource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Resource.html) › OAuth2CredentialProvider
Implements: [IResource](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.IResource.html), [IOAuth2CredentialProvider](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.IOAuth2CredentialProvider.html), [IGrantable](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IGrantable.html), [IEnvironmentAware](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.IEnvironmentAware.html), IOAuth2CredentialProviderRef, IConstruct, IDependable
Obtainable from: OAuth2CredentialProvider.usingAtlassian, OAuth2CredentialProvider.usingAuth0, OAuth2CredentialProvider.usingCognito, OAuth2CredentialProvider.usingCustom, OAuth2CredentialProvider.usingCyberArk, OAuth2CredentialProvider.usingDropbox, OAuth2CredentialProvider.usingFacebook, OAuth2CredentialProvider.usingFusionAuth, OAuth2CredentialProvider.usingGithub, OAuth2CredentialProvider.usingGoogle, OAuth2CredentialProvider.usingHubspot, OAuth2CredentialProvider.usingLinkedin, OAuth2CredentialProvider.usingMicrosoft, OAuth2CredentialProvider.usingNotion, OAuth2CredentialProvider.usingOkta, OAuth2CredentialProvider.usingOneLogin, OAuth2CredentialProvider.usingPingOne, OAuth2CredentialProvider.usingReddit, OAuth2CredentialProvider.usingSalesforce, OAuth2CredentialProvider.usingSlack, OAuth2CredentialProvider.usingSpotify, OAuth2CredentialProvider.usingTwitch, OAuth2CredentialProvider.usingX, OAuth2CredentialProvider.usingYandex, OAuth2CredentialProvider.usingZoom

- CloudFormation: [`AWS::BedrockAgentCore::OAuth2CredentialProvider`](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-bedrockagentcore-oauth2credentialprovider.html)
- L1 type: [`CfnOAuth2CredentialProvider`](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.CfnOAuth2CredentialProvider.html)
- Source: [`aws-bedrockagentcore/lib/identity/oauth2-credential-provider.ts`](https://github.com/aws/aws-cdk/blob/v2.278.0/packages/aws-cdk-lib/aws-bedrockagentcore/lib/identity/oauth2-credential-provider.ts#L773)
- Type last changed: v2.255.0 · 19 May 2026

## Example

TypeScript:

```ts
agentcore.OAuth2CredentialProvider.usingCustom(this, "CustomOAuthMeta", {
  clientId: "your-client-id",
  clientSecret: cdk.SecretValue.unsafePlainText("your-client-secret"),
  authorizationServerMetadata: {
    issuer: "https://idp.example.com",
    authorizationEndpoint: "https://idp.example.com/oauth2/authorize",
    tokenEndpoint: "https://idp.example.com/oauth2/token",
  },
});
```

Python:

```python
agentcore.OAuth2CredentialProvider.using_custom(self, "CustomOAuthMeta",
    client_id="your-client-id",
    client_secret=cdk.SecretValue.unsafe_plain_text("your-client-secret"),
    authorization_server_metadata=agentcore.OAuth2AuthorizationServerMetadata(
        issuer="https://idp.example.com",
        authorization_endpoint="https://idp.example.com/oauth2/authorize",
        token_endpoint="https://idp.example.com/oauth2/token"
    )
)
```

Java:

```java
OAuth2CredentialProvider.usingCustom(this, "CustomOAuthMeta", CustomOAuth2CredentialProviderProps.builder()
        .clientId("your-client-id")
        .clientSecret(SecretValue.unsafePlainText("your-client-secret"))
        .authorizationServerMetadata(OAuth2AuthorizationServerMetadata.builder()
                .issuer("https://idp.example.com")
                .authorizationEndpoint("https://idp.example.com/oauth2/authorize")
                .tokenEndpoint("https://idp.example.com/oauth2/token")
                .build())
        .build());
```

C#:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
OAuth2CredentialProvider.UsingCustom(this, "CustomOAuthMeta", new CustomOAuth2CredentialProviderProps {
    ClientId = "your-client-id",
    ClientSecret = SecretValue.UnsafePlainText("your-client-secret"),
    AuthorizationServerMetadata = new OAuth2AuthorizationServerMetadata {
        Issuer = "https://idp.example.com",
        AuthorizationEndpoint = "https://idp.example.com/oauth2/authorize",
        TokenEndpoint = "https://idp.example.com/oauth2/token"
    }
});
```

Go:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
agentcore.OAuth2CredentialProvider_UsingCustom(this, jsii.String("CustomOAuthMeta"), &CustomOAuth2CredentialProviderProps{
	ClientId: jsii.String("your-client-id"),
	ClientSecret: cdk.SecretValue_UnsafePlainText(jsii.String("your-client-secret")),
	AuthorizationServerMetadata: &OAuth2AuthorizationServerMetadata{
		Issuer: jsii.String("https://idp.example.com"),
		AuthorizationEndpoint: jsii.String("https://idp.example.com/oauth2/authorize"),
		TokenEndpoint: jsii.String("https://idp.example.com/oauth2/token"),
	},
})
```

## Initializer

TypeScript:

```ts
new OAuth2CredentialProvider(scope: Construct, id: string, props: OAuth2CredentialProviderProps)
```

Python:

```python
OAuth2CredentialProvider(scope: Construct, id: str, props: OAuth2CredentialProviderProps)
```

Java:

```java
new OAuth2CredentialProvider(Construct scope, String id, OAuth2CredentialProviderProps props)
```

C#:

```csharp
new OAuth2CredentialProvider(Construct scope, string id, OAuth2CredentialProviderProps props)
```

Go:

```go
NewOAuth2CredentialProvider(Scope Construct, Id *string, Props OAuth2CredentialProviderProps)
```

## Construct Props

- `credentialProviderVendor`: string (required) — OAuth2 vendor string for CloudFormation `CredentialProviderVendor`.

- `oAuth2CredentialProviderName`: string — Name of the credential provider.

  **Default:** a name generated by CDK

- `oauth2ProviderConfigInput`: [CfnOAuth2CredentialProvider.Oauth2ProviderConfigInputProperty](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_bedrockagentcore.CfnOAuth2CredentialProvider.Oauth2ProviderConfigInputProperty.html) (required) — OAuth2 provider configuration passed through to `Oauth2ProviderConfigInput`.

- `tags`: { [key: string]: string } — Tags for this credential provider.

  **Default:** no tags

## Properties

- `callbackUrl`: string — Callback URL for the OAuth2 authorization flow.

- `clientSecretArn`: string — The ARN of the Secrets Manager secret for the OAuth2 client credentials.

  May be undefined for resources imported without this attribute.

- `createdTime`: string — Timestamp when the credential provider was created.

- `credentialProviderArn`: string — The ARN of this credential provider.

- `credentialProviderVendor`: string — OAuth2 vendor string passed to CloudFormation.

- `env`: [ResourceEnvironment](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.ResourceEnvironment.html) — The environment this resource belongs to.

  For resources that are created and managed in a Stack (those created by
  creating new class instances like `new Role()`, `new Bucket()`, etc.), this
  is always the same as the environment of the stack they belong to.

  For referenced resources (those obtained from referencing methods like
  `Role.fromRoleArn()`, `Bucket.fromBucketName()`, etc.), they might be
  different than the stack they were imported into.

- `grantPrincipal`: [IPrincipal](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_iam.IPrincipal.html) — The principal to grant permissions to.

- `lastUpdatedTime`: string — Timestamp when the credential provider was last updated.

- `node`: [Node](https://docs.aws.amazon.com/cdk/api/v2/docs/constructs.Node.html) — The tree node.

- `oAuth2CredentialProviderName`: string — The name of this OAuth2 credential provider.

- `oAuth2CredentialProviderRef`: [OAuth2CredentialProviderReference](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.interfaces.aws_bedrockagentcore.OAuth2CredentialProviderReference.html) — A reference to a OAuth2CredentialProvider resource.

- `PROPERTY_INJECTION_ID`: string (static) — Uniquely identifies this class.

- `stack`: [Stack](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.Stack.html) — The stack in which this resource is defined.

## Methods

- `applyCrossStackReferenceStrength(strength: ReferenceStrength): void` — Override the cross-stack reference strength for this resource.

  When set, any cross-stack reference to this resource will use the specified
  mechanism instead of the global default determined by the
  `@aws-cdk/core:defaultCrossStackReferences` context key. This is useful for
  selectively weakening specific references to avoid the "deadly embrace" problem
  without changing the app-wide default.

  **Parameters**

  - `strength` — - The reference strength to use for this resource.

- `applyRemovalPolicy(policy: RemovalPolicy): void` — Apply the given removal policy to this resource.

  The Removal Policy controls what happens to this resource when it stops
  being managed by CloudFormation, either because you've removed it from the
  CDK application or because you've made a change that requires the resource
  to be replaced.

  The resource can be deleted (`RemovalPolicy.DESTROY`), or left in your AWS
  account for data recovery and cleanup later (`RemovalPolicy.RETAIN`).

- `bindForGatewayOAuthTarget(scopes: string[], customParameters?: { [key: string]: string }): GatewayOAuth2IdentityBinding` — ARNs and OAuth scopes for {@link GatewayCredentialProvider.fromOauthIdentity } / {@link GatewayCredentialProvider.fromOauthIdentityArn }.

  **Parameters**

  - `scopes` — OAuth scopes the gateway target should request (see vendor documentation).
  - `customParameters` — Optional custom parameters for the OAuth flow.

- `fromOAuth2CredentialProviderAttributes(scope: Construct, id: string, attrs: OAuth2CredentialProviderAttributes): IOAuth2CredentialProvider` (static) — Import an existing OAuth2 credential provider.

- `grant(grantee: IGrantable, ...actions: string[]): Grant` — [disable-awslint:no-grants].

- `grantAdmin(grantee: IGrantable): Grant` — [disable-awslint:no-grants].

- `grantFullAccess(grantee: IGrantable): Grant` — [disable-awslint:no-grants].

- `grantRead(grantee: IGrantable): Grant` — [disable-awslint:no-grants].

- `grantUse(grantee: IGrantable): Grant` — [disable-awslint:no-grants].

- `isConstruct(x: any): boolean` (static) — Checks if `x` is a construct.

  Use this method instead of `instanceof` to properly detect `Construct`
  instances, even when the construct library is symlinked.

  Explanation: in JavaScript, multiple copies of the `constructs` library on
  disk are seen as independent, completely different libraries. As a
  consequence, the class `Construct` in each copy of the `constructs` library
  is seen as a different class, and an instance of one class will not test as
  `instanceof` the other class. `npm install` will not create installations
  like this, but users may manually symlink construct libraries together or
  use a monorepo tool: in those cases, multiple copies of the `constructs`
  library can be accidentally installed, and `instanceof` will behave
  unpredictably. It is safest to avoid using `instanceof`, and using
  this type-testing method instead.

  **Parameters**

  - `x` — Any object.

  **Returns:** true if `x` is an object created from a class which extends `Construct`.

- `isOwnedResource(construct: IConstruct): boolean` (static) — Returns true if the construct was created by CDK, and false otherwise.

- `isResource(construct: IConstruct): boolean` (static) — Check whether the given construct is a Resource.

- `toString(): string` — Returns a string representation of this construct.

- `usingAtlassian(scope: Construct, id: string, props: AtlassianOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Atlassian OAuth2.

- `usingAuth0(scope: Construct, id: string, props: IncludedOauth2TenantCredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Auth0 OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingCognito(scope: Construct, id: string, props: IncludedOauth2TenantCredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Amazon Cognito OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingCustom(scope: Construct, id: string, props: CustomOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for a custom OAuth2 authorization server (discovery document or metadata).

- `usingCyberArk(scope: Construct, id: string, props: IncludedOauth2TenantCredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for CyberArk OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingDropbox(scope: Construct, id: string, props: DropboxOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Dropbox OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingFacebook(scope: Construct, id: string, props: FacebookOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Facebook OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingFusionAuth(scope: Construct, id: string, props: IncludedOauth2TenantCredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for FusionAuth OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingGithub(scope: Construct, id: string, props: GithubOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for GitHub OAuth2.

- `usingGoogle(scope: Construct, id: string, props: GoogleOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Google OAuth2.

- `usingHubspot(scope: Construct, id: string, props: HubspotOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for HubSpot OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingLinkedin(scope: Construct, id: string, props: LinkedinOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for LinkedIn OAuth2.

- `usingMicrosoft(scope: Construct, id: string, props: MicrosoftOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Microsoft (Entra ID) OAuth2.

- `usingNotion(scope: Construct, id: string, props: NotionOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Notion OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingOkta(scope: Construct, id: string, props: IncludedOauth2TenantCredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Okta OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingOneLogin(scope: Construct, id: string, props: IncludedOauth2TenantCredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for OneLogin OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingPingOne(scope: Construct, id: string, props: IncludedOauth2TenantCredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for PingOne OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingReddit(scope: Construct, id: string, props: RedditOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Reddit OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingSalesforce(scope: Construct, id: string, props: SalesforceOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Salesforce OAuth2.

- `usingSlack(scope: Construct, id: string, props: SlackOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Slack OAuth2.

- `usingSpotify(scope: Construct, id: string, props: SpotifyOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Spotify OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingTwitch(scope: Construct, id: string, props: TwitchOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Twitch OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingX(scope: Construct, id: string, props: XOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for X (Twitter) OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingYandex(scope: Construct, id: string, props: YandexOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Yandex OAuth2 (`IncludedOauth2ProviderConfig`).

- `usingZoom(scope: Construct, id: string, props: ZoomOAuth2CredentialProviderProps): OAuth2CredentialProvider // chainable` (static) — Create a credential provider for Zoom OAuth2 (`IncludedOauth2ProviderConfig`).

- `with(...mixins: IMixin[]): IConstruct` — Applies one or more mixins to this construct.

  Mixins are applied in order. The list of constructs is captured at the
  start of the call, so constructs added by a mixin will not be visited.
  Use multiple `with()` calls if subsequent mixins should apply to added
  constructs.
