Behavior Customization | ZITADEL Docs
Behavior Customization
In this guide, you will create a ZITADEL action. After users register using an external identity provider, the action assigns them a role.
Prerequisites
Before you start, make sure you have everything set up correctly.
- You need to be at least a ZITADEL ORG_OWNER
- Your ZITADEL organization needs to have the actions feature enabled.
- Your ZITADEL organization needs to have at least one external identity provider enabled
- You need to have at least one role configured for a project
Copy some information for the action
- Select the Projects navigation item.
- Select a project that has a role configured.
- Copy the Project ID on the screen's top right.
- Scroll to the ROLES section and note some roles key.
Create the action
- Select the Actions navigation item.
- In the Actions section, select the + New button.
- Give the new action the name
addGrant. - Paste this snippet into the multiline text-field.
- Replace the snippets placeholders and select Save.
/**
* Add a usergrant to a new created/registered user
*
* Flow: Internal Authentication or External Authentication, Trigger: Post creation
*
* @param ctx
* @param api
*/
function addGrant(ctx, api) {
api.userGrants.push({
projectID: '<the projects resource ID>',
roles: ['<the role key>']
});
}
Run the action when a user registers
Now, make the action hook into the external authentication flow.
- In the Flows section, select the + New button.
- Select the Flow Type External Authentication.
- Select the Trigger Type Post Creation.
- In the Actions dropdown, check addGrant.
- Select the Save button.
New users automatically are assigned a role now if they register by authenticating with an external identity provider.