How to Configure OAuth 2.0 Authentication for an API Target
Last updated: November 20, 2026
OAuth 2.0 lets Astra get its own access tokens and renew them while it tests your API. You enter your identity provider's details once, and Astra doesn't need a new token for every scan.
Before you start
Collect these from your identity provider:
The Access token URL.
The Client ID and Client secret of an application that is allowed to call your API.
A Username and Password for a test user, only if you use the Password Credentials grant type.
Optional: an Audience and any extra parameters your token endpoint needs.
Use credentials for a test environment and an account that can reach every endpoint you want tested.
Choose the grant type
Grant type | Use it when |
|---|---|
Client Credentials | Your application signs in as itself, with no user. This is the usual choice for service-to-service APIs. |
Password Credentials | Your application signs in as a specific user with a username and password. This flow is also called Resource Owner Password. |
If you are not sure, ask the team that runs your identity provider which flow your API expects.
Set up OAuth 2.0
Open the Targets page.
For a target that is still being set up, click Setup on its row and open the Authentication section. For an active target, click the settings icon on its row and open API Auth under Target Setup.
Under Authentication type, select OAuth 2.0. The API Auth page shows the OAuth 2.0 fields.
Select the Grant type: Password Credentials or Client Credentials.
Fill in the fields:
Access token URL. The address your identity provider uses to issue tokens, for example
https://example.com/login/oauth/access_token. Astra must be able to reach it.Client ID. The identifier of your application, for example
7a45b9fd-12c3-4e56-a789-0123456789ab.Client secret. The secret that belongs to the Client ID.
Username and Password. Required only for Password Credentials. Leave them empty for Client Credentials.
Audience. Optional. Fill it in if your identity provider requires an audience.
Extra params. Optional. A JSON object with any other parameters your token endpoint needs, for example
{"scope": "read"}.
Save your entries:
On the setup page, they save automatically a moment after you stop typing.
In the settings of an active target, click Save Changes.
Astra adds the authorization header to every request it sends, so you don't build the header yourself.
In this example, the target's API Auth page uses OAuth 2.0 with the Client Credentials grant type:

If none of the authentication types in the list fits your API, use the Try a Custom Script instead link under the fields.
Update saved credentials
Astra hides saved secrets after you save them, and shows Saved secrets are hidden. Leave every field blank to keep them, or re-enter all authentication details to update.
To keep the saved details, leave every field blank.
To change one, enter all of the authentication details again. If some are missing, Astra shows Re-enter all authentication details to update saved secrets.
Check that it works
After you upload a Postman collection, you can check that the credentials work. Read more in 📄 How to verify API credentials in a Postman collection.
Troubleshooting
The token request fails
What you see: Astra can't sign in to your API.
What to do:
Check that the Access token URL is correct and reachable from the internet.
Check that the Client ID and Client secret are correct and haven't been rotated.
Check that the application is allowed to use the grant type you selected.
The test user's details are wrong, or the password flow is off
What you see: The token endpoint returns an error when you use Password Credentials.
What to do: Confirm the test user's credentials, and confirm the password flow is enabled for your application.
The collection holds different credentials
What you see: Requests still return 401 Unauthorized. Astra signs in with the details in Authentication. Requests from your Postman collection use the credentials inside the collection and its environment file.
What to do: Make sure both places hold valid credentials. If you use a fixed token instead of OAuth 2.0, it must stay valid for the whole scan, because a token that expires partway through makes every later request fail.
A required field is empty or in the wrong format
What you see: Save Changes doesn't save.
What to do: Fill in the fields marked as required. Grant type, Access token URL, Client ID and Client secret are always required, and Username and Password are required for Password Credentials.