14

I'm building a client application in Node.js for creating new JIRA issues and I want to authenticate users using OAuth. The Atlassian docs are pretty bad for Jira and Oauth newcomers. So, I'm looking for a single example that describes exactly how to set up the JIRA application link, and the how to build a basic app in node that connects to Jira via OAuth. I'm not sure where else to look. (I'm using JIRA v6.0.4)

2

2 Answers 2

3

There is an example for Node.JS with OAuth in the Atlassian repo that Brian also mentioned. I think it is for the 2-legged authentication.

It needs a pre-negotiated consumer key already set up by you. Here is an example how to obtain a token you can save in your config file: https://developer.atlassian.com/jiradev/api-reference/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-oauth-authentication

Sign up to request clarification or add additional context in comments.

1 Comment

Don't forget to check the issues of this repo and user solutions. It's quite old and needs updating!
1

Here's a blog describing node.js and jira authentication using Oauth

It is in an express framework. I paste some part of the code below.

var base_url = "YOUR_JIRA_BASE_URL"; //example https://test.atlassian.net

app.get('/jira', function(req, res) {

var oa = new OAuth(base_url + "/plugins/servlet/oauth/request-token", //request token
    base_url + "/plugins/servlet/oauth/access-token", //access token
    "mykey", //consumer key 
    "YOUR_PEM_FILE_CONTENT", //consumer secret, eg. fs.readFileSync('jira.pem', 'utf8')
    '1.0', //OAuth version
    "http://localhost:1337/jira/callback", //callback url
    "RSA-SHA1");
oa.getOAuthRequestToken(function(error, oauthToken, oauthTokenSecret) {
    if (error) {
        console.log(error.data);
        response.send('Error getting OAuth access token');
    } else {
        req.session.oa = oa;
        req.session.oauth_token = oauthToken;
        req.session.oauth_token_secret = oauthTokenSecret;
        return res.redirect(base_url + "/plugins/servlet/oauth/authorize?oauth_token=" + oauthToken);
    }
});
});

If anyone is confused about any part of the code, you can add comment to this answer.

1 Comment

Hi, about the oauth_callback: What URL shall I supply and where do I configure that URL in Jira-Admin? Is it the ApplicationURL or the Authorize URL or another? Does Jira forward the browser to that URL after accepting the request or does Jira create a separate connection to it and thus the URL needs to be public? Setting it to "oob" works, but then the user has to copy the secret... developer.atlassian.com/server/jira/platform/oauth

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.