Can someone tell me why i may be experiencing an error when attempting to display my JWT?

Connection function:

function Connect(server, sId, aId, password) {
  console.log("Creating connection")
  var postData = {Server: server, SId: sId, AId: aId, Password: password}
  var strData = JSON.stringify(postData);
  // creating Json web token
  const token = jwt.sign({strData}, process.env.TOKEN_SECRET, {algorithm: "HS512"});
  MakeConnectionRequest('//path', strData, token); 
}

Request where I’m attempting to display the token within the authorisation header.

function MakeConnectionRequest(path, data, token) {

  const options = 
  {
     
    method: 'POST',
    protocol: 'https:',
    hostname: '', // leaving empty
    //port: 443,
    path: `${path}`,
    rejectUnauthorized: false,
    headers: {
    'Content-Type': 'application/json',
    'Content-Length': 89,
    'authorisation': `${token}` // im trying to insert the token here.
    
  },  
};

const request = https.request(options, res => {
  console.log(`statusCode: ${res.statusCode}`)

  res.on('data', d => {
    process.stdout.write(d)
  })
})

request.on('response', (response) => {
  console.log(`STATUS: ${response.statusCode}`);
  console.log(`HEADERS: ${JSON.stringify(response.headers)}`);
  response.on('data', (chunk) => {
    console.log(`BODY: ${chunk}`);
  })
  response.on('end', () => {
    console.log('No more data in response.')
  });
});
request.on('error', error => {
  console.error(error)
})

request.write(data, 'utf-8');
request.end();

}

In the terminal it doesn’t return a token it shows “www-authenticate”: “Bearer”. Does anyone know why this may be? There’s not much content online regarding client requests in electron, usually i would go onto YouTube for an in depth explanation but i cant find anything.

Thankyou!

Replace with

'Authorization': `Bearer ${token}`

Hey I’ve literally just tried that! but I ended up getting:

“www-authenticate” : "Bearer error="invalid_token", error_description="The signature is invalid"

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.