How to store metadata of authorization in TFML

In Testfully, authorization settings can be defined at multiple levels, including request, folder, collection and environment. When using file-based workspaces with Testfully Markup Language (TFML), authorization metadata can be stored in the relevant .toml files. This article demonstrates how to persist authorization metadata in TFML.

Defining authorization in TFML

When a file accepts authorization settings, one of the following fields can be added to the file to define the authorization scheme and its parameters:

FieldAuthorization Type
basic_authBasic Authorization

basic_auth field

The basic_auth field is an object that defines settings for Basic Authorization. It can include the following properties:

PropertyTypeDescription
usernameStringThe username for Basic Authorization.
passwordStringThe password for Basic Authorization.
bearerBooleanWhat header should be used for Bearer token authentication. Defaults to "Authorization".
prefixStringThe prefix to use for the Authorization header. Defaults to "Basic".

In most cases, you would want to use basic authorization setting using the following syntax:

# request.toml
[basic_auth]
username = "teddybear"
password = "S3cret"

Read below for details on each property.

username field

The username field is a string that defines the username for Basic Authorization. It is mandatory, and must not be empty. Ideally, you want to use a variable for the username, so that it can be easily changed without modifying the TFML file.

Example below defines a Basic Authorization with a username variable:

# request.toml
[basic_auth]
username = "{{username}}"

password field

The password field is a string that defines the password for Basic Authorization. It is mandatory, and must not be empty. Ideally, you want to use a variable for the password, so that it can be easily changed without modifying the TFML file.

Example below defines a Basic Authorization with a password variable:

# request.toml
[basic_auth]
password = "{{password}}"

bearer field

Most likely, you don't need to set a value for the bearer field as it's optional and defaults to the standard "Authorization" header. However, if you are meant to pass the basic auth token in a different header, you can set the bearer field to the desired header name. Then again, it's very unlikely you would need to do that.

Example below defines a Basic Authorization with a custom bearer header:

# request.toml
[basic_auth]
username = "{{username}}"
password = "{{password}}"
bearer = "x-access-token" # This is very unlikely to be needed, but here it is anyway.

prefix field

Basic Authorization uses the "Basic" prefix by default to indicate the type of the authorization token so you rarely need to set this value as it's optional and Testfully will use "Basic" if not specified. However, if you need to use a different prefix for some reason, you can set the prefix field to the desired value.

Example below defines a Basic Authorization with a custom prefix:

# request.toml
[basic_auth]
username = "{{username}}"
password = "{{password}}"
prefix = "BasicAuth"