Skip to content

Rules ​

Using serverless JavaScript scripting one can execute custom code based on user events or for populating attributes or claims.

User Event Rules ​

An user event rule allow extensive customization. Interact with your provisioning system, analytics environment or CRM system.

.javascript
/*

*/
// default user_event code

function main({
  before, // the old user object (SCIM representation)
  after, // the new user object (SCIM representation)
  type, // Could be create, replace, patch, delete
  me, // if the user used the SCIM /Me endpoint
  callback,
  variables
}) {
  
  if(before == null){
    callback(
      [
        // Uncomment the line below and change the email template id and to-address
        new Email(variables.emailTemplate0).to('arietimmerman@gmail.com').setData({ user: JSON.stringify(after)}),
      ]
    );
  }else if(attributeChanged(before, after, 'emails')){
    callback(
      [
      ]
    );
  }else{
    callback(
      [
        // do nothing, byt still invoke the callback-function. Elsewise, the script will never end (well... it will timeout)
      ]
    );
  }

}
/*

*/
// default user_event code

function main({
  before, // the old user object (SCIM representation)
  after, // the new user object (SCIM representation)
  type, // Could be create, replace, patch, delete
  me, // if the user used the SCIM /Me endpoint
  callback,
  variables
}) {
  
  if(before == null){
    callback(
      [
        // Uncomment the line below and change the email template id and to-address
        new Email(variables.emailTemplate0).to('arietimmerman@gmail.com').setData({ user: JSON.stringify(after)}),
      ]
    );
  }else if(attributeChanged(before, after, 'emails')){
    callback(
      [
      ]
    );
  }else{
    callback(
      [
        // do nothing, byt still invoke the callback-function. Elsewise, the script will never end (well... it will timeout)
      ]
    );
  }

}

Attribute Rules ​

An attribute rule is used to populate attributes in id_token, userinfo and SAML Assertion responses.

This is an example rule.

.javascript
// default attribute code
function ({
  subject,
  context,
  callback,
  variables
}) {

  callback(

    {
      attributes: {
        subject: subject,
        context: context
      }
    }
    
  );

}
// default attribute code
function ({
  subject,
  context,
  callback,
  variables
}) {

  callback(

    {
      attributes: {
        subject: subject,
        context: context
      }
    }
    
  );

}