Hi Community,
I am trying to connect my nodejs app to my jira instance, where I have my app installed.
I have saved all the tenant information on a json file "tenant.json", but when I try to generate a JWT to query my instance I am getting a "401 Unauthorized"
This is the code:
var jwt = require('atlassian-jwt');
var moment = require('moment');
var fetch = require('node-fetch');
var tenant = require('./tenant.json');
issue = '10001';const myreq = jwt.Request = jwt.fromMethodAndUrl('GET', '/rest/api/2/issue/' + issue);
const now = moment().utc();
const tokenData = {
"iss": tenant.clientKey,
"iat": now.unix(),
"exp": now.add(3, 'minutes').unix(),
"qsh": jwt.createQueryStringHash(myreq)
};
const token = jwt.encode(tokenData, tenant.sharedSecret);
fetch(tenant.baseUrl + '/rest/api/2/issue/' + issue,
{
method: 'GET',
headers: {
'Authorization': 'JWT ' + token,
'Accept': 'application/json'
}
}).then(response => {
console.log(`Response: ${response.status} ${response.statusText}`);
}).catch(err => console.error(err));
Can someone help?