I need help converting a rule to action

function addClasslinkTenantIdToAccessToken(user, context, callback) {
    if (context.connection.match(/Classlink/)) {
        context.accessToken.classlink_tenant_id = user.classlink_tenant_id
    }
    return callback(null, user, context)
}

When I’m using the action editor the data shape looks very different. In the action the only property for accessToken is a string and not an object so I’m not sure how to convert that part.

What I have now

exports.onExecutePostLogin = async (event, api) => {
  if (event.connection.name.match(/Classlink/)) {

  }
};

Hey @paperjt welcome to the community!

You’ll want to test of course, but I think the following should work:

exports.onExecutePostLogin = async (event, api) => {
  // Check if the connection type includes "Classlink"
  if (event.connection.name.match(/Classlink/)) {
    // Assign the classlink_tenant_id from the user profile to the access token as a custom claim
    const classlinkTenantId = event.user.classlink_tenant_id;
    api.accessToken.setCustomClaim('classlink_tenant_id', classlinkTenantId);
  }
};

1 Like

Is there a way to see this change in the auth0 logs? If I look at the log entry for Successful Login, on the Action Details tab I see that the action was successful but I don’t see classlink_tenant_id in any of the data on the log entry.

edit: nm, I just switched testing from auth0 UI’s tester to my app so I could get the token and decode it to see

1 Like

Great! Glad that worked for you :slight_smile:

1 Like