Custom claims / flat roles - Actions V2 with n8n

Hello hello!
I’m in the process of migrating my whole 2 actions from V1 to V2 - namely auto role assignment and flat roles. I’m doing so with n8n.

I just got auto role assignment to work reliably by setting up a webhook, getting user info, performing some checks on the user and finally using the /zitadel.authorizarion.v2.AuthorizationService/CreateAuthorization API endpoint.
My n8n webhook here is trigger under method: /zitadel.user.v2.UserService/AddHumanUser. Such that when a new user is created, external or internal, the n8n flow is run and the new user is auto assigned the desired role.

Now I need to figure out flat roles or custom claims in a similar way. I’ve defined my webhook and and it triggers on function: preaccessToken. Everything looks good here. I’m also able to extract the roles to create a simple json object. However, how do I insert this back into the access token? I tried using n8ns respond to webhook node, but the flow seems to fail. Any ideas here? I ran through the actions v2 custom claims example on github but got confused lol.

As a side note, for stuff like flat roles, it would be better if it were maintained alongside the new actions. It’s quite a basic requirement
Was this page helpful?