Closed dimisizz closed 3 years ago
What password
are you using? You may need to specify an API token
Specify a password for this tool to authenticate all requests with. Cloud users need to generate an API token for this value.
https://confluence.atlassian.com/cloud/api-tokens-938839638.html
@mtjandra-applyboard I tried using the password I used to login JIRA via chrome and tried using API token generated from https://id.atlassian.com/manage/api-tokens. Nothing is working. I think my JIRA is not cloud version. I think it is server version.
You may forget add strictSSL: false
if you are using self-hosting jira.
I am also attempting to authenticate using an api token and I have not had success. I'm on jira cloud and getting a deprecation error:
401 - "Basic authentication with passwords is deprecated. For more information, see: https://confluence.atlassian.com/cloud/deprecation-of-basic-authentication-with-passwords-for-jira-and-confluence-apis-972355348.html\n"
When directly calling the api, I can just set this header: Authorization: 'Basic ${apiToken}'
, is there an equivalent option I could pass here? I noticed that using the api token as a password also requires I add a username which should not be needed
I noticed that using the api token as a password also requires I add a username which should not be needed
@BenAlderfer Not sure where this assumption comes from but the documentation clearly says that the user's email is needed. See https://confluence.atlassian.com/cloud/api-tokens-938839638.html
@pioug I was referring to basic auth which actually does have the username in it, but its encoded with the token into a single string: https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/#supplying-basic-auth-headers
@BenAlderfer Oh ok. No, I don't think it's possible to set directly the authorization header.
This is working for me for jira-client@^8.2.2
exports.loginJira = async function (username, password, bearerToken) {
let jiraObj = {
protocol: "https",
host: someObject.jira.url,
apiVersion: "2",
strictSSL: true,
bearer: bearerToken,
};
if (bearerToken) {
jiraObj.bearer = bearerToken;
} else {
jiraObj.username = username;
jiraObj.password = password;
}
let jira = new JiraApi(jiraObj);
return jira
.getCurrentUser()
.then((result) => {
console.log("Login Success");
return { result, message: "Login successful", success: true };
})
.catch((err) => {
console.log("Login Failed Check creds");
return { err, message: "Login unsuccessful", success: false };
});
};
This is my code:
I expect the program to print issue.fields.status.name in my terminal but I encounter Request failed with status code 401.
I am sure my username and password are correct because I can access JIRA application via chrome and I can see the detail of this IssueNumber.
I don't know why I encounter 401 error. Can anyone help me?