Example Scripts
The scripts below are executed by the OneWelcome Extension Engine during Custom Registration.
Refer to the OneWelcome Extension Engine documentation for help writing scripts. It is recommended to use properties for variables that differ per environment, e.g. URLs, and/or contain sensitive data, e.g. passwords.
Init Script
function execute(requestPayload) {
return {
status: 2000,
responsePayload: ""
};
}
Complete Script
The complete script requires a user
object with a defined id
property to be returned. The amr
property is optional (requires
extension-engine 2.5.0
or later). The user
object may also contain any other attributes describing the authenticated user, these attributes are exposed in the id_token
as well as via the UserInfo and Token introspection APIs.
function execute(requestPayload) {
var userId = "userId_" + Date.now();
return {
status: 2000,
user: {
id: userId,
amr: ["mfa", "pwd"],
firstName: "John",
lastName: "Doe",
email: "[email protected]"
}
};
}
Backchannel Communication Script
function execute(requestPayload) {
var userId = requestPayload.userId;
var uniqueIdentifier = userId+"_"+Date.now();
CACHE.store(uniqueIdentifier, userId); //Another script could use CACHE.fetch(...) to retrieve the stored value
return {
status: 2000,
responsePayload: uniqueIdentifier
};
}
Status Codes
When writing a custom script, these status code ranges should be used.
Status | Description |
---|---|
2xxx | Success |
4xxx | Failed, user can try again |
5xxx | Failed, cleanup actions should be triggered and user must start at beginning again |