Authentication

The Authentication scheme in BullMQ Proxy is currently pretty simple. You add a list of valid comma separated tokens as an env variable (AUTH_TOKENS), and then for every request made to the proxy send one of those valid tokens as a BEARER token.

curl --location 'http://localhost:8080/queues/my-test-queue/jobs' \
--header 'Authorization: Bearer 1234'

Sometimes, an endpoint that is processing a job will need to communicate with the proxy, for example for updating a job's progress status or adding logs to the job. This requires a different token, which is actually provided in the body of the call. For example, if the endpoint was implemented in NodeJS it would look something along these lines:

const http = require('node:http');

// Create an HTTP server
const server = http.createServer((req, res) => {
  const { job, token } = JSON.parse(req.body);
  
  // Do something with the job
  await doSomething(job);
  
  // Update progress to 100
  const updateProgress = await fetch(`http://localhost:8080/queues/my-test-queue/jobs/${job.id}/progress`, {
    method: 'POST',
    body: JSON.stringify(100),
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${token}`
    }
  });

  res.writeHead(200, { 'Content-Type': 'application/json' });
  res.end(JSON.stringify('job-result'));
});

Last updated