Skip to main content

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​

Step 1: Generate an OAuth2 Key​

  1. Sign in to the API Portal & AI Hub, and go to Keys › OAuth2 Keys.

  2. Click Register OAuth2 client.

  3. Enter the following details.

    FieldDescription
    Key managerRequired. Select ThunderID.
    Application nameRequired. A name for the key.
    Grant typesRequired. Select Client credentials.
  4. Click Register client.

  5. Copy the consumer secret, and store it securely.

warning

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​

  1. On the OAuth2 Keys page, find your key, and click Get token on its row. The Get an access token dialog opens.

  2. Enter the Consumer secret. Optionally, enter Scopes and Resource indicators.

  3. 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​

  1. In the portal, open the API, and under Endpoints, copy the Production endpoint.

  2. Send the access token as a bearer token.

    curl -X GET "<endpoint>/<resource-path>" \
    -H "Authorization: Bearer <access-token>"
note

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​

Was this page helpful?