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)
-
1Have you had any success? There is a Node.js example on Atlassian's Bitbucket, which is here: bitbucket.org/atlassian_tutorial/atlassian-oauth-examples.Brian– Brian2013-09-11 17:45:35 +00:00Commented Sep 11, 2013 at 17:45
-
1Take a look at this answer - might be helpful for you: stackoverflow.com/a/19116334/129815Serge Broslavsky– Serge Broslavsky2013-10-01 14:30:02 +00:00Commented Oct 1, 2013 at 14:30
2 Answers
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
1 Comment
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
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