How to use user token in a workflow?

When a workflow triggered how can I make possible to use {{$nToken}} ?

(I don’t want to create API Key. It should be user token)

Seems an X-Y question. What scenario do you want to use {{$nToken}} for?

I have a second docker image which get some request from nocobase and take action according to user’s demand. I have to know which user it is to insert a new record on nocobase (docker will send some information to nocobase via a creating new record)

For short answer: there is no way to use {{$nToken}} in workflow, neither in anywhere of server side. This variable can only be used in client side.

I guess what you need is to determine which user is in the workflow context, is it?

By using different trigger type of workflows, there are different way to get user information.

  • Collection event: createdById / updatedById in trigger data of trigger variables.
  • Post-action event: User acted in trigger variables.

Commonly between different NocoBase apps, the users are not same, either. Unless you did some sync on users collection.

The only way to use it may like:

  1. Synced user collection and data between both apps (A and B).
  2. Same API_KEY in .env in both apps (A and B).
  3. Add a custom request action button in app A.
  4. Configure to pass {{$nToken}} in header as Authorization: Bearer <token>.
  5. Configure the request URL points to http://<B>/api/someResourceBindingWorkflow.
  6. Use the user variable in workflow in app B.

If I’m wrong on the scenario, please let us know more specific of yours.

1 Like

Here is a scenario,

  1. When user create a new form, a workflow will be triggered,
  2. Workflow will take an action on different docker/service (Workflow node will send some http action or anything like that)
  3. Then, this server will do its job and create a new record on nocobase with nocobase’s rest api.

I don’t want to create and give Nocobase’s ApiKey to this docker/service.

Thank you for your interest and kindness.

Seems you want to create the JWT in server side (workflow). By now, the only way to do this is by using JavaScript node in workflow, which let you do some coding to sign a new JWT based on some user (data). Or you may need to extend a specific node type in a plugin to achieve.

1 Like