Depending on the type of authentication or authorization your API requires, you can add auth settings to an API test at three levels: the test, a flow, and a single request. mabl supports the following authentication types for API tests:
- API key
- Basic auth
- Bearer token
- OAuth 1.0
- OAuth 2.0
Auth settings cascade down from the test. By default, flows and requests are set to Inherit from parent and use the auth of the level above them, so you can set auth once for the whole test and override it only where a flow or request needs something different.
If you need support for additional authentication types, please let us know via the mabl Product Portal.
Test-level auth
Test-level auth applies to every request in the test that doesn't set its own. If the API doesn't require auth, leave it set to No auth.
To apply auth settings to all requests in an API test, take the following steps:
- Click on the Edit test properties pencil in the top-left corner of the API Test Editor.
- In the edit test modal, select the authentication method that the API requires.
- Enter auth details as required by the API.
- Close the edit test modal.
Adding test-level auth
Flow-level auth
By default, a flow uses the test's auth. Select a different method to give every request in the flow its own auth instead. Flow-level auth settings override test-level auth settings.
To apply different auth settings to all requests in an API flow, take the following steps:
- Click on the pencil to edit the flow in the API Test Editor.
- In the Auth tab, select the authentication method that the API requires.
- Enter the auth details as required by the API.
- Close the edit flow modal.
Adding flow-level auth
When you update flow-level auth in one test, you update the auth across all instances of the flow in your workspace.
Request-level auth
By default, a request uses the auth of the level above it:
- A request inside a flow uses the flow's auth. If the flow is also set to Inherit from parent, the request uses the test's auth.
- A request outside any flow uses the test's auth.
If no level above the request sets auth, the request is sent without auth. To override the inherited auth, select a different method on the request.
To apply auth settings to a specific request in an API test, open the test in the API Test Editor and take the following steps:
- In the step builder for a given request, click on the Auth tab.
- Select the authentication method that the request requires.
- Enter auth details as required by the API.
Adding request-level auth
Example: send a token from a login request as a bearer token
Some APIs return a token from a login request, which later requests send as a bearer token. You can handle this by combining the levels:
- Set up the login request with the auth it needs.
- In the login request, create a variable from the response, such as
tokenfrom the JSON body. - After the login request, put the requests that need the token in a flow.
- In the flow's auth settings, select Bearer token and enter
{{@token}}as the token.
Every request in the flow now sends the token from the login response.
Auth settings in Postman imports
If you imported a Postman collection with auth settings, see Authorization settings in Postman imports to learn how mabl imports them.