I’m trying to hook up my app to the JIRA API. I found this cool Node.js module that’s supposed to make it easier, but I’m stuck on the login part.
Here’s what I’ve got so far:
const JiraClient = require('jira-connector');
const jira = new JiraClient({
host: 'my-jira-instance.com',
port: 443,
protocol: 'https',
username: 'myusername',
password: 'mypassword',
apiVersion: '2.0'
});
jira.user.getUser({ username: jira.username }, (err, user) => {
if (err) {
console.error('Oops:', err.message);
return;
}
console.log('Yay, it worked!');
});
But when I run it, I get this error:
401: Unauthorized - Can't get user info
I’m pretty sure my login details are correct. What am I missing here? Any tips would be awesome!
I encountered similar issues when trying to use basic authentication with JIRA. After some trials, I discovered that switching to OAuth resolved the problem in my case. I set up an application link in my JIRA instance and obtained the necessary consumer key, private key, token, and token secret. I then modified my JiraClient configuration to include an oauth object instead of using username and password. Here is an example:
const jira = new JiraClient({
host: 'my-jira-instance.com',
oauth: {
consumer_key: 'your-consumer-key',
private_key: 'your-private-key',
token: 'your-access-token',
token_secret: 'your-token-secret'
}
});
This approach resolved my authentication issues, and it might be worth checking if your JIRA instance requires OAuth or any additional configuration changes.
hey emma, have u tried using api tokens instead of password? jira’s been moving away from basic auth. go to ur jira account settings, create an api token, and use that instead of ur password in the config. might solve ur issue without dealing with oauth stuff. good luck!
I’ve encountered this issue before. It’s likely related to JIRA’s security policies. Have you verified that your account has the necessary permissions to access the API? Sometimes, even with correct credentials, insufficient permissions can cause authentication failures. Additionally, check if your JIRA instance requires two-factor authentication. If it does, you’ll need to use an API token instead of your password. You can generate one in your JIRA account settings. Lastly, ensure your JIRA instance allows API access from external sources. Some admins restrict this for security reasons. If none of these solve the problem, you might need to consult your JIRA administrator for specific configuration details.