OAuth POST fails with oauth_problem=signature_invalid but GET passes

nirajmchauhan October 6, 2017

I am facing an issue in my Node Application. While making a POST request to create Issue endpoint, it always fails with oauth_problem=signature_invalid.

But when I make a GET request to other endpoints, it works.

My code:

const fs = require('fs');
const OAuth = require('oauth').OAuth;
const config = require('./config');
var payload = {// ... };

const consumer = new OAuth(
    `${config.baseUrl}/plugins/servlet/oauth/request-token`,
    `${config.baseUrl}/plugins/servlet/oauth/access-token`,
    config.consumerKey,
    fs.readFileSync('./keys/jira_privatekey.pem', 'utf8'),
    "1.0",
    "http://example.com",
    "RSA-SHA1");

consumer.post(`${config.baseUrl}/rest/api/2/issue/`, config.accesToken, config.tokenSecret, payload, (e, data, resp) => {
    console.log(e);
    console.log(data);
});

 

I double checked the URLs, and all of them are correct.

Error:

oauth_problem=signature_invalid

6 answers

0 votes
Coskun Aydinoglu January 18, 2023

I had the same issue. JSON.stringfy the body of the request solved the issue. I also added signature 


const consumer = new OAuth.OAuth(
requestTokenURL,
accessTokenURL,
config.api_consumer_key,
privateKey,
"1.0",
"RSA-SHA1",
null,
(base_string, key) => {
console.log("base_string:", base_string);
console.log("key:", key);
return crypto.createSign('RSA-SHA1').update(base_string).sign(key, 'base64');
});

consumer.post(
config.api_url + options.uri,
result.oauth.access_token,
result.oauth.token_secret,
JSON.stringify(options.body),
'application/json',
function(err, data, res) {
if (err) {
console.log(err);
callback();
}
else {
console.log(res.statusCode, data);
callback();
}
}
);
0 votes
Petter Måhlén March 18, 2020

I had this issue as well. In my case, the problem was solved by adding a 'Content-Type' header specifying 'application/json'. Seems like a case of incorrect error reporting; the signature was in fact fine (as others have stated), but the way JIRA (in my case) extracted the signature broke down when it didn't understand the request payload.

0 votes
Raphael_Pioger October 21, 2019

Hi guys,

 

I dig up an old topic, but today I'm facing exactly the same issue, after having followed this topic: https://developer.atlassian.com/server/jira/platform/oauth/

The symptom is the same: POST fails with 401 error as per the sample provided in the link of above, when I execute a simple requestToken.

Untitled.png

But changing it to GET works, or a kind of as it returns null string:Untitled1.png

I also tried to set up useBodyEncodingForURI to false as described here, but it changed nothing.

What can be the root cause for that ?

Thanks for your help

 

R.

mainaksethi November 21, 2019

worked for you? I am stuck exactly here.

Raphael_Pioger November 28, 2019

Not yet.

I switched to something else, but I guess the code needs to be refresh. This is something I'll try later

0 votes
keshav October 14, 2019

// here 1. post_body in string
// 2. project key
//3. issuetyepe :Not all project in jira have same issue type as Bug. may some project not support issuetype as Bug
// check correct issue type allowed to project.

    var postBody= `{
                     "fields": {
                     "project":{ "key": "PROJECT_KEY_HERE"
                     },
                     "summary": "using JIRA REST API",
                     "description": "Creating of an issue using project keys and issue type names using the REST API", 
                    
  "issuetype": {                              
"name": "Bug"                           
}                      
 }                    
}`;



consumer
.post(`${JiraURL}jira/rest/api/2/issue/`,
          result.oauthAccessToken,
          result.oauthAccessTokenSecret,                            
postBody,
"application/json",             
function (errordata) {
//handle your error and data
});

 

This is late but may helpful to some one.

0 votes
Ashish Jain March 27, 2018

Hi Guys, 

Any update on this....Facing the same issue

Jack Sarle March 27, 2018

So one thing that was messing up my consumer connection was that my post body wasn't a string so then in the consumer library it was changing the 'applicaiton/json' type to a different content type and that was why it was failing. 

 

 

SO MAKE SURE YOUR POST_BODY IS A STRING

 

*edit for emphasis

0 votes
Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 6, 2017

Hi! 

Please, have a look this knowledge base:

https://confluence.atlassian.com/kb/oauth-error-oauth_problem-signature_invalid-720406720.html

 

Cheers, 

Gonchik Tsymzhitov

nirajmchauhan October 6, 2017

Hi,

Please correct me if I am wrong:

Base URL is where my JIRA is hosted. eg: dev.domain.org.com

Following this tutorial, I have set my Application URL to http://example.com

As you can see above in code, I have passed as http://example.com.

 

Am I still missing something? This is a console application, its not behind firewall or nginx proxy.

Gonchik Tsymzhitov
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 6, 2017

Application url is node app link. 

Just try to generate under this docs

https://github.com/lakshmi-kannan/jira-oauth-access-token-generator/blob/master/generate_access_token.py

nirajmchauhan October 6, 2017

But my node is not hosted anywhere, its a console application. How will I get the node app link?

 

I generated access token using this guide

Jack Sarle February 25, 2018

Nirajmchauhan have you found a solution for this? I am in the exact same position as you?

Like Ben Pearson likes this

Suggest an answer

Log in or Sign up to answer