camunda / camunda-8-js-sdk

The Camunda 8 JavaScript SDK for Node.js
https://camunda.github.io/camunda-8-js-sdk/
Apache License 2.0
19 stars 6 forks source link

Self Hosting : Erroring requesting token for Client Id zeebe #273

Open hassan-alnator opened 3 weeks ago

hassan-alnator commented 3 weeks ago

An error is happening when the sdk is trying to request a token with self hosted environments

Screenshot 2024-10-31 at 9 26 20 PM

Environment Variables Screenshot 2024-10-31 at 9 26 41 PM

Client ID & Client Secret Screenshot 2024-10-31 at 9 26 48 PM

Environment

Screenshot 2024-11-01 at 10 08 10 AM

Sample Code

import { Camunda8 } from '@camunda8/sdk'

import 'dotenv/config'; 

const c8 = new Camunda8()
const zeebe = c8.getZeebeGrpcApiClient()
const tasklist = c8.getTasklistApiClient()

console.log('Starting worker...')
zeebe.createWorker({
    taskType: 'service-task',
    taskHandler: (job) => {
        console.log(`[Zeebe Worker] handling job of type ${job.type}`)
        return job.complete({
            serviceTaskOutcome: 'We did it!',
        })
    },
})

console.log(`Starting human task poller...`)
setInterval(async () => {
    const res = await tasklist.searchTasks({
        state: 'CREATED',
    })
    if (res.length > 0) {
        console.log(`[Tasklist] fetched ${res.length} human tasks`)
        res.forEach(async (task) => {
            console.log(
                `[Tasklist] claiming task ${task.id} from process ${task.processInstanceKey}`
            )
            const t = await tasklist.assignTask({
                taskId: task.id,
                assignee: 'demobot',
                allowOverrideAssignment: true,
            })
            console.log(
                `[Tasklist] servicing human task ${t.id} from process ${t.processInstanceKey}`
            )
            await tasklist.completeTask(t.id, {
                humanTaskStatus: 'Got done',
            })
        })
    } else {
        console.log('No human tasks found')
    }
}, 3000)

const p = await zeebe.createProcessInstanceWithResult({
    bpmnProcessId: `c8-sdk-demo`,
    variables: {
        humanTaskStatus: 'Needs doing',
    },
});

console.log(`[Zeebe] Finished Process Instance ${p.processInstanceKey}`)
console.log(`[Zeebe] humanTaskStatus is "${p.variables.humanTaskStatus}"`)
console.log(`[Zeebe] serviceTaskOutcome is "${p.variables.serviceTaskOutcome}"`)

SDK Component

Zeebe, operate and tasklist

Expected Behavior

The SDK should authenticate and proceed to create a process instance

Current Behavior

Erroring requesting token for Client Id zeebe

Steps to Reproduce

  1. using the env and the code
  2. run the code using ts-node or bun
  3. error happens

Context (Environment)

Self hosting using the default docker compose

jwulf commented 3 weeks ago

Hi @hassan-alnator, could you please make a minimal reproducer that I can check out and run locally? That way we know we are talking about the exact same thing as we step through it.

hassan-alnator commented 3 weeks ago

I uploaded the exact example and all its files here: https://github.com/hassan-alnator/camunda-8-sdk-example

just run the "main.ts" file

jwulf commented 2 weeks ago

Ah, when you say "just run the main.ts file", what command is it?

ts-node main.ts and tsc && node main.js both fail on my machine.

Update:

tsc --init && tsc && node main.js did it.

jwulf commented 2 weeks ago

I'm using these credentials:

# Self-Managed
export ZEEBE_ADDRESS='localhost:26500'
export ZEEBE_REST_ADDRESS='http://localhost:8080'
export ZEEBE_GRPC_ADDRESS='localhost:26500'
export ZEEBE_CLIENT_ID='zeebe'
export ZEEBE_CLIENT_SECRET='zecret'
export CAMUNDA_OAUTH_URL='http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token'
export ZEEBE_AUTHORIZATION_SERVER_URL='http://localhost:18080/auth/realms/camunda-platform/protocol/openid-connect/token'
export CAMUNDA_TASKLIST_BASE_URL='http://localhost:8082'
export CAMUNDA_OPERATE_BASE_URL='http://localhost:8081'
export CAMUNDA_OPTIMIZE_BASE_URL='http://localhost:8083'
export CAMUNDA_MODELER_BASE_URL='http://localhost:8070/api'
export CAMUNDA_ZEEBE_OAUTH_AUDIENCE='zeebe.camunda.io'

# Needed for Multi-Tenancy
export CAMUNDA_TENANT_ID='<default>'

# TLS for gRPC is on by default. If the Zeebe broker is not secured by TLS, turn it off
export CAMUNDA_SECURE_CONNECTION=false
export ZEEBE_INSECURE_CONNECTION=true

export CAMUNDA_OAUTH_TOKEN_REFRESH_THRESHOLD_MS=10000

export CAMUNDA_AUTH_STRATEGY=OAUTH

export CAMUNDA_OPTIMIZE_OAUTH_AUDIENCE="optimize-api"

I get an error because the bpmn is not found, since no model is deployed in the example code.

Error: 5 NOT_FOUND: Command 'CREATE_WITH_AWAITING_RESULT' rejected with code 'NOT_FOUND': Expected to find process definition with process ID 'c8-sdk-demo', but none found
    at callErrorFromStatus (/Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/call.js:31:19)
    at Object.onReceiveStatus (/Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/client.js:193:76)
    at /Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/call-interface.js:78:35
    at Object.onReceiveStatus (/Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@camunda8/sdk/dist/zeebe/lib/GrpcClient.js:102:36)
    at InterceptingListenerImpl.onReceiveStatus (/Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/call-interface.js:73:23)
    at Object.onReceiveStatus (/Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:360:141)
    at Object.onReceiveStatus (/Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/client-interceptors.js:323:181)
    at /Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/resolving-call.js:129:78
    at process.processTicksAndRejections (node:internal/process/task_queues:85:11)
for call at
    at ServiceClientImpl.makeUnaryRequest (/Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/client.js:161:32)
    at ServiceClientImpl.<anonymous> (/Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@grpc/grpc-js/build/src/make-client.js:105:19)
    at /Users/jwulf/workspace/camunda-8-sdk-example/node_modules/@camunda8/sdk/dist/zeebe/lib/GrpcClient.js:306:47
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5) {
  code: 5,
  details: "Command 'CREATE_WITH_AWAITING_RESULT' rejected with code 'NOT_FOUND': Expected to find process definition with process ID 'c8-sdk-demo', but none found",
  metadata: Metadata {
    internalRepr: Map(2) {
      'content-type' => [ 'application/grpc' ],
      'grpc-status-details-bin' => [
        Buffer(156) [Uint8Array] [
            8,   5,  18, 151,   1,  67, 111, 109, 109,  97, 110, 100,
           32,  39,  67,  82,  69,  65,  84,  69,  95,  87,  73,  84,
           72,  95,  65,  87,  65,  73,  84,  73,  78,  71,  95,  82,
           69,  83,  85,  76,  84,  39,  32, 114, 101, 106, 101,  99,
          116, 101, 100,  32, 119, 105, 116, 104,  32,  99, 111, 100,
          101,  32,  39,  78,  79,  84,  95,  70,  79,  85,  78,  68,
           39,  58,  32,  69, 120, 112, 101,  99, 116, 101, 100,  32,
          116, 111,  32, 102, 105, 110, 100,  32, 112, 114, 111,  99,
          101, 115, 115,  32,
          ... 56 more items
        ]
      ]
    },
    options: {}
  }
}
hassan-alnator commented 2 weeks ago

based on this error I think because am using bun it already wraps everything with an async function just wrap the zeebe.createProcessInstanceWithResult with an async function .

( async () => {
    const p = await zeebe.createProcessInstanceWithResult({
        bpmnProcessId: `c8-sdk-demo`,
        variables: {
            humanTaskStatus: 'Needs doing',
        },
    });
})();
jwulf commented 2 weeks ago

The error is because there is no model deployed. The reproducer needs a .bpmn file and a call to deployResources to deploy it.

hassan-alnator commented 2 weeks ago

c8-sdk-demo.bpmn.zip

BPMN File attached, but the error happens before starting any process

jwulf commented 1 week ago

I sent a PR against the MR. I can't get it to throw the error that you are seeing. Let's get the patched MR running on your machine, so that we are looking at the same code and state, and then see how to break it the way you are seeing.