Skip to main content

Context configuration

What this step is for​

Some applications need the user to choose something after signing in, for example a workspace, an account, a region or a project. You cannot ask for it on the credentials form, because the list of choices comes from the application itself and is available only once the user is signed in.

This step defines those extra questions. They are asked once, when the user connects the application, right after the sign-in succeeds. The answers are saved and used again every time Canvas signs in later, so the user is not asked again.

Triggered by: Application registration (after successful authentication).

If your application needs no extra choice, leave this step empty.

What you see on the page​

ItemWhat it does
Instructions (HTML)A short text shown above the questions, for example "Choose the workspace to connect".
Fields ConstructorBuild the questions one by one.
JSON editorThe same questions as text. The two views stay in sync: a change in one shows up in the other.
Add new contextAdds a question.

Settings of a question​

SettingWhat to enter
Short nameA short identifier without spaces, for example workspaceId. The answer is saved under this name, and your scripts read it as appVault.workspaceId (or appVaultSecret.workspaceId).
NameThe label users see.
DescriptionA hint shown with the question.
TypeHow the user answers: a text box, a drop-down list, radio buttons, check boxes, a multi-line text, a lookup table (two lists to move items between) or a date picker.
MultipleThe user may choose several values.
OptionalThe user may skip the question.
HiddenThe question is not shown to the user.
SecretThe answer is saved in the secret storage (appVaultSecret) instead of the settings storage (appVault). Turn it on for anything sensitive.
ScriptOptional. A script that loads the choices from the application, for example the list of workspaces.

Loading choices with a script​

Add a script when the choices must come from the application. The script runs when the question is shown. It can use appVault and appVaultSecret (so it can use the access token saved in the previous step) and api.send(...) to call the application. It must return:

PropertyMeaning
shortNameOverrides ShortName property in constructor.
optionsThe list of choices: { label, value }, where label is what the user sees and value is what is saved.
valueThe preselected value (a list of values for Multiple).
sourceOptions / targetOptionsFor a lookup table: the available items and the chosen items.
hiddentrue to hide the question. Overrides Hidden property in constructor

Example: let the user choose a workspace.

const r = await api.send({
verb: 'GET',
baseUrl: appVault.baseUrl,
requestUrl: 'workspaces',
headers: { Authorization: `Bearer ${appVaultSecret.access_token}` }
});
return {
value: appVault.workspaceId || '',
options: r.items.map(w => ({ label: w.name, value: w.id }))
};

For the full list of what the script can use and return, see Context field script.

If the script fails, the user sees the error and cannot answer the question, so test it on the Authentication step first.

Where the answers go​

  • Each answer is saved under the question's short name, in appVault or, if Secret is on, in appVaultSecret.
  • The next steps and later sign-ins can read them. For example, in the Authorization step: appVault.workspaceId.
  • Answers in appVault can also be read in workflow and block scripts with api.GetAppVault().

Anything sensitive must be marked Secret. appVault can be read from workflow scripts.

Good to know​

  • The question names (short names) are used in scripts. Do not rename them after users have connected the application.