Skip to content
Talk to an Engineer Dashboard

Automatically assign roles

Automatically assign roles to users in your application by mapping directory provider groups to application roles using Scalekit

Manually assigning roles to users in your application consumes time and creates room for errors for your customers (usually, administrators). Scalekit monitors role changes in connected directories and notifies your application through webhooks. You use the event payload to keep user roles in your application in sync with directory groups in near real time.

Organization administrators commonly manage varying access levels by grouping users in their directory. For example, to manage access levels to GitHub, they create groups for each role and assign users to those groups. In this case a Maintainer group includes all the users who should have maintainer access to the repository.

Group-based role assignmentDirectory ProvidersYour ApplicationScalekitEngineering GroupEditor RoleManagers GroupAdmin Role

This enables your application to take necessary actions such as creating or modifying user roles as directed by the organization’s administrators.

To enable administrators to map directory groups to roles in your app, complete these steps:

  1. Open the Scalekit dashboard.
  2. Go to Roles & Permissions.
  3. Use the Roles and Permissions sections to configure your application’s authorization model.
  4. Register your app’s roles and permissions so Scalekit can reference them in mappings and webhook events.

Select Add role to create a new role.

Choose clear display names and descriptions for your roles. This helps customers understand and align the roles with the access levels they already maintain in their directory.

Scalekit roles configuration page showing list of application roles

The roles page lists a couple of sample roles by default. You can edit or remove these and add new roles that match your application’s authorization model.

Scalekit roles list showing default and custom roles

Specify the default roles your app wants to assign to the organization creator and to members who belong to the same organization. All added roles are available for you to select as default roles.

Scalekit default roles configuration for creators and members

After you create roles, they represent the roles in your app that you want directory groups to control. Users receive role assignments in your app based on the groups they belong to in their directory.

You can set up this mapping in two ways:

  1. Configure mappings in the Scalekit dashboard on behalf of organization administrators. Select the organization and go to the SCIM provisioning tab.
  2. Share the admin portal link with organization administrators so they can configure the mappings themselves.

Scalekit automatically displays mapping options in both the Scalekit dashboard and the admin portal. This allows administrators to connect organization groups to app roles without custom logic in your application.

Mapping directory groups to application roles in Scalekit

Scalekit continuously monitors updates from your customers’ directory providers and sends event payloads to your application through a registered webhook endpoint. To set up these endpoints and manage subscriptions, use the Webhooks option in the Scalekit dashboard.

Listen for the organization.directory.user_updated event to determine a user’s roles from the payload. Scalekit automatically includes role information that is relevant to your app, based on the roles you configured in the Scalekit dashboard.

Create a webhook endpoint for role updates
// Webhook endpoint to receive directory role updates
app.post('/webhook', async (req, res) => {
// Extract event data from the webhook payload
const event = req.body;
const { email, roles } = event.data;
console.log('Received directory role update for:', email);
// Extract role_name from the roles array, if present
const roleName = Array.isArray(roles) && roles.length > 0 ? roles[0].role_name : null;
console.log('Role name received:', roleName);
// Business logic: update user role and permissions in your app
if (roleName) {
await assignRole(roleName, email);
console.log('Updated access for user:', email);
}
res.status(201).json({
message: 'Role processed',
});
});

Refer to the list of directory webhook events you can subscribe to for more event types.