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)

Ciaran Donoghue
  • 800
  • 3
  • 22
  • 46
Colyn Brown
  • 508
  • 1
  • 5
  • 11
  • 1
    Have you had any success? There is a Node.js example on Atlassian's Bitbucket, which is here: https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples. – Brian Sep 11 '13 at 17:45
  • 1
    Take a look at this answer - might be helpful for you: http://stackoverflow.com/a/19116334/129815 – Serge Broslavsky Oct 01 '13 at 14:30

2 Answers2

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

Koshinae
  • 2,240
  • 2
  • 30
  • 40
  • 2
    Don't forget to check the issues of this repo and user solutions. It's quite old and needs updating! – Mouneer Oct 24 '16 at 16:28
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.

L4reds
  • 412
  • 2
  • 5
  • 21
  • 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... https://developer.atlassian.com/server/jira/platform/oauth/ – nitzel Aug 14 '18 at 15:56