Auth

Say once how the API authenticates, and CLEM adds the credentials to every request: Basic, a Bearer token, an API key, or OAuth 2.0 with tokens it gets and renews for you.

Example flow

examples/Help/auth.clem.json: Basic, Bearer and an API key against httpbin.org, which echoes back what it received.

Flow auth and request auth

The Auth tab of a request set to Bearer token with $token
A request's Auth tab with a Bearer token from a variable.

Every field takes $vars, so credentials can live in an environment or, better, a secret. The log and reports mask them. A header the request sets itself (Authorization…) wins over its auth. A $var in an auth field that has no value is sent as written, and the log warns: Auth (Basic): $password has no value, so it was sent as written. Check the variable's name, or set the secret's value.

The types

TypeFieldsSends
BasicUsername, passwordAuthorization: Basic base64(user:password)
Bearer tokenToken, prefix (Bearer)Authorization: Bearer <token>
API keyName, value, in (header or query)X-Api-Key: … or ?api_key=…
OAuth 2.0Grant, token URL, client id / secret, scope…Authorization: Bearer <access token> (or ?access_token=)

The common pattern, a login request that returns a token, is in the tutorial: extract $token from the login's response, and set the flow's auth to Bearer token $token.

OAuth 2.0

CLEM gets the token before the first request that needs it, adds it, renews it when it expires (with the refresh token when there is one) and, when the server answers 401 to a saved token, gets a new one and sends the request once more.

GrantFor
Client credentialsService-to-service APIs: client id and secret only.
PasswordA user's name and password, for APIs that still allow it.
Authorization code (with PKCE)Signing in as a user: CLEM opens a sign-in window the first time.

Tokens stay in memory until the app closes, never in the flow. Forget tokens in the auth settings signs in again.

Exported flows get their own tokens when they run. They can't open a sign-in window, so for the authorization code grant give them a refresh token (for example $refreshToken, set with --set or an environment).

From imports

Postman, Bruno, OpenAPI and cURL imports bring their auth along: a collection's auth becomes the flow's, a folder's or a request's own goes to the request's Auth tab, and curl -u / --oauth2-bearer set Basic / Bearer. Import.