X
X can be configured as an AgentCore Identity credential provider for outbound resource access. This allows your agents to authenticate users through X’s OAuth2 service and obtain access tokens for X API resources.
Outbound
Note
AgentCore Identity issues a unique OAuth2 callback URL for each credential provider you create. The unique callback URL enables session binding, which protects the OAuth2 authorization-code exchange against cross-provider replay and CSRF-style attacks by ensuring an authorization response can only be redeemed against the specific credential provider that initiated it. Because the URL is unique per provider, you won’t know it until after you call CreateOauth2CredentialProvider. Create your X OAuth2 client first, then return to the X developer console to register the callback URL once AgentCore Identity has issued it.
Step 1: Create the X OAuth2 client
Use the following procedure to set up an X OAuth2 application and obtain the necessary client credentials for AgentCore Identity. You will register the redirect URI in Step 3, after AgentCore Identity issues the unique callback URL.
To configure an X OAuth2 application
-
Open the X developer portal.
-
In the left navigation bar, choose Project & Apps.
-
Choose on the X project you’ve created for the application.
-
Under the Apps header choose Add an App.
-
Choose Create new.
-
Provide a name and description for your application.
-
In the left navigation bar, choose the application that was just generated.
-
On the app details page for your new app, choose Edit in the User Authentication settings.
-
Select the App permissions necessary for your application.
-
For Type of App select Web App, Automated App or Bot.
-
Under App Info , leave the callback URL field empty for now — you will add the unique callback URL in Step 3.
-
For Website URL enter the URL for your application.
-
Choose Save.
-
Under the Keys and token tab for your application, go to the OAuth 2.0 Client ID and Client Secret.
-
Choose Generate and note the client ID and secret that get generated as you’ll need this information to configure the X resource provider in AgentCore Identity.
Note
X only displays the full client secret when it is generated, if you lose this information you’ll need to re-generate the client secret in the X developer portal.
For more details, refer to X’s OAuth 2.0 documentation
Step 2: Create the AgentCore Identity credential provider
To configure X as an outbound resource provider, use the following:
{ "name": "X", "credentialProviderVendor": "XOauth2", "oauth2ProviderConfigInput" : { "includedOauth2ProviderConfig": { "clientId": "your-client-id", "clientSecret": "your-client-secret" } } }
The CreateOauth2CredentialProvider response includes a callbackUrl field. This URL is unique to this credential provider and looks like: https://bedrock-agentcore.us-east-1.amazonaws.com/identities/oauth2/callback/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX. Save this value for the next step.
Step 3: Register the unique callback URL with X
Return to the X developer console and add the unique callback URL to your OAuth2 application’s redirect URI list.
-
Sign in to the X developer console and open the OAuth2 application you created in Step 1.
-
Add the
callbackUrlvalue returned byCreateOauth2CredentialProviderto the application’s redirect URI configuration. -
Save your changes.