Consume an OAuth2-Secured API
An OAuth2-secured API expects an access token issued by a key manager. ThunderID is the default key manager, so you can generate a key and a token in the API Portal & AI Hub without any other setup.
Prerequisites
- The API has the JWT Auth policy attached in the API Control Plane, and is published to the portal. See OAuth2 Authentication.
- An account in the portal. See Sign In to the Portal.
Step 1: Generate an OAuth2 Key
-
Sign in to the API Portal & AI Hub, and go to Keys › OAuth2 Keys.
-
Click Register OAuth2 client.
-
Enter the following details.
Field Description Key manager Required. Select ThunderID. Application name Required. A name for the key. Grant types Required. Select Client credentials. -
Click Register client.
-
Copy the consumer secret, and store it securely.
The consumer secret is shown only once. The portal does not store it, and you need it each time you get an access token. If you lose it, delete the key and generate a new one.
Step 2: Get an Access Token
-
On the OAuth2 Keys page, find your key, and click Get token on its row. The Get an access token dialog opens.
-
Enter the Consumer secret. Optionally, enter Scopes and Resource indicators.
-
Click Get token, and copy the access token.
The token is shown only once, and is valid until it expires. When it expires, get a new one in the same way.
Step 3: Invoke the API
-
In the portal, open the API, and under Endpoints, copy the Production endpoint.
-
Send the access token as a bearer token.
curl -X GET "<endpoint>/<resource-path>" \-H "Authorization: Bearer <access-token>"
If the API has other policies attached, such as subscription validation or API key authentication, send the credentials that those policies expect as well. See Which Credentials You Need.
Next Steps
- OAuth2 Keys - Get a token with curl, use a custom key manager, and edit or delete keys
- Which Credentials You Need - Find out which credentials an API expects
- Consume an API-Key-Secured API - Invoke an API secured with an API key
Was this page helpful?