Skip to main content

Authentication method types

Ecosystem provides four authentication method types: Basic Auth, OAuth 2, API Key and Custom. The type determines the configuration fields and what Ecosystem applies automatically during an execution.

Basic Auth​

Stores a username and a password. Ecosystem automatically adds the Authorization: Basic xxx header.

ParameterTypeRequiredDefaultDescription
UsernameString✅—Sign-in identifier required by the service.
PasswordString (masked)✅—Password, or reference to a dictionary variable.

OAuth 2​

Stores OAuth 2 information. Ecosystem acquires the token and refreshes it automatically when it expires.

ParameterTypeRequiredDefaultDescription
Client IDString✅—OAuth client ID.
Client SecretString (masked)✅—OAuth client secret, or reference to a dictionary variable.
Token URLURL✅—URL used to obtain the token.
ScopeList❌—Requested OAuth scopes, one per field.
Scope transmission

Each scope entered is transmitted when requesting a token. An empty field is ignored. If no scopes are entered, the scope parameter is not included in the request.

API Key​

Stores an API key transmitted via HTTP headers and/or query parameters. Ecosystem automatically injects these values when the method is selected in an HTTP Request, Agent or Code node.

ParameterTypeRequiredDefaultDescription
HeadersKey-value pairs❌—Headers to inject (e.g. x-api-key → {{dictionaries.secrets.apiKey}}).
Query paramsKey-value pairs❌—Parameters added to the URL (e.g. api_key → my_key).

In a Code node, access the values via libs.ecosystemCredentials.get('alias').getHeaders() or .getQueryParams().

Custom​

Executes custom code that manages a token and its expiration date. Useful when the authentication server does not use a standard supported by Ecosystem.

ParameterTypeRequiredDefaultDescription
Token locationHeader, Params or Cookie✅—Where the token is placed on the request.
NameString✅—Name of the header, parameter or cookie (e.g. Authorization).
ValueString✅—Injected value (e.g. Bearer {{accessToken}}).
CodeJavaScript✅—Script returning { accessToken, expiresIn }.

Code output format​

The code must return an object containing accessToken and expiresIn:

  • accessToken: the authentication token used for the request;
  • expiresIn: the token validity duration, in seconds.
{
"accessToken": "__token_value__",
"expiresIn": 300
}

Code example​

The code can use all the features of a Code node (dictionaries, libs.axios, etc.).

// Generate the Basic Auth from the dictionaries
const basicHeader = Buffer.from(`${dictionaries.oauth.clientId}:${dictionaries.oauth.clientSecret}`).toString('base64');

// Call the token endpoint to obtain access_token
const { data: response } = await libs.axios.post('https://auth.api.com/oauth/token', {
grant_type: 'client_credentials'
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: `Basic ${basicHeader}`
}
});

// Return the token and the validity duration
return {
accessToken: response.access_token,
expiresIn: response.expires_in // In seconds
};