How do I convert this rule to action?

As rule is deprecating in near future, I want to convert this rule to action:

function (user, context, callback) {

  user.awsRole = 'arn:aws:iam::1234567890:role/Auth0v2,arn:aws:iam::1234567890:saml-provider/Auth0';
  user.awsRoleSession = user.name;

  context.samlConfiguration.mappings = {
    'https://aws.amazon.com/SAML/Attributes/Role': 'awsRole',
    'https://aws.amazon.com/SAML/Attributes/RoleSessionName': 'awsRoleSession'
  };

  callback(null, user, context);

}

I tried to convert it as following for action:

exports.onExecutePostLogin = async (event, api) => {
 const user = event.user;
  user.awsRole = 'arn:aws:iam::1234567890:role/Auth0v2,arn:aws:iam::1234567890:saml-provider/Auth0';
};

However it shows the warning:

Property 'awsRole' does not exist on type 'User & { multifactor?: string[] | undefined; } & { identities: UserIdentity[]; }'.(2339)

This worked for me:

exports.onExecutePostLogin = async (event, api) => {
  api.samlResponse.setAttribute("https://aws.amazon.com/SAML/Attributes/Role", "arn:aws:iam::1234567890:role/Auth0v2,arn:aws:iam::1234567890:saml-provider/Auth0");
  api.samlResponse.setAttribute("https://aws.amazon.com/SAML/Attributes/RoleSessionName", event.user.name);
};

Good general info here on migrating from rules to actions, and check out these references on the event and api objects

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.