Skip to content

OAuth2 Issues #269

Open
Open
@cmerther

Description

@cmerther

Hello,

I am trying to use jira.js to read project info and write issues to my jira project. I'm using atlassian's OAuth (3LO) authentication flow. The scopes that I use for this login are read:jira-work write:jira-work read:me offline_access.

I was reading over issue #231 and found out about https://api.atlassian.com/oauth/token/accessible-resources and the api at https://api.atlassian.com/ex/jira/{cloudId}/rest/api/3.

After much trial and error I've got one endpoint working through a raw get request https://api.atlassian.com/ex/jira/{cloudId}/rest/api/3/project/{jiraProjectKey} which will return information. However when I try to do the same call through the library it doesn't find any project with that key.

//`https://site.atlassian.net/rest/api/3/project/${jiraProjectKey}` interestingly does not work
//this will work
axios.get(`https://api.atlassian.com/ex/jira/${cloudId}/rest/api/3/project/${jiraProjectKey}`, {
    headers: {
        Authorization: `Bearer ${accessToken.access_token}`
    }
}).then(response => {
    console.log('success', response.data);
}).catch(error => {
    console.log('err', error);
});


const jira = new Version3Client({
    // I've tried settings the host to the api.atlassian.com base but it produces the same results. which I think was the solution for #231 
    // host: `https://api.atlassian.com/ex/jira/${cloudId}`,
    host: 'https://site.atlassian.net',
    newErrorHandling: true,
    authentication: {
        oauth2: {
            accessToken: `Bearer ${accessToken.access_token}`,
        },
    },
});

//this does not work, can't find the project key or id
const resp = await jira.projects.getProject({ projectIdOrKey: settings.jiraProjectKey });
console.log('lib resp', resp);

Any ideas what I'm doing wrong?

Metadata

Metadata

Assignees

Labels

questionRaised for inquiries, clarifications, or discussions related to the project.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions