Jira REST API Oauth signature invalid on POST, but GET has no problems

I'm using DevDefined.Oauth to get my Oauth header. It works perfectly fine for my GET request, but when I use it for POST requests it returns oauth_problem=oauth_signature invalid.

 

 

private static String GetDevDefinedOauthHeader(String consumerKey, String consumerSecret, IToken accessToken, Uri requestUri, AsymmetricAlgorithm jKey, String restMethod)
{
OAuthConsumerContext consumerContext = new OAuthConsumerContext
{

ConsumerKey = consumerKey,
SignatureMethod = SignatureMethod.RsaSha1,
ConsumerSecret = consumerSecret,
UseHeaderForOAuthParameters = true,
Key = jKey
};

OAuthSession oSession = new OAuthSession(consumerContext)
{
AccessToken = new TokenBase
{
Token = accessToken.Token,
ConsumerKey = accessToken.ConsumerKey,
TokenSecret = accessToken.TokenSecret,
SessionHandle = accessToken.SessionHandle
}
};
IConsumerRequest consumerRequest = oSession.Request();
consumerRequest = ConsumerRequestExtensions.ForMethod(consumerRequest, restMethod);
consumerRequest = ConsumerRequestExtensions.ForUri(consumerRequest, requestUri);
consumerRequest = consumerRequest.SignWithToken();
 return consumerRequest.Context.GenerateOAuthParametersForHeader();
}

 

 

This is my GET request:

String oauthHeader = GetDevDefinedOauthHeader(consumerKey, consumerSecret, sessionAccessToken, new Uri(baseUrl + "/rest/api/latest/issue/" + issueKey), key, "GET");

 String newHeader = header.Split(' ')[1];

hClient.DefaultRequestHeaders.Accept.Clear();
hClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

hClient.SetAuthorization("OAuth", newHeader);

HttpResponseMessage response = await hClient.GetAsync("/rest/api/latest/issue/HW-1");

 

 

This is my POST request:

String oauthHeader = GetDevDefinedOauthHeader(consumerKey, consumerSecret, sessionAccessToken, new Uri(baseUrl + "/rest/api/latest/issue/" + issueKey), key, "POST");

 String newHeader = header.Split(' ')[1];

hClient.DefaultRequestHeaders.Accept.Clear();
hClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

hClient.SetAuthorization("OAuth", newHeader);

HttpResponseMessage response = await hClient.PostAsJsonAsync("/rest/api/latest/version", versionObject);

1 answer

UPADTE:

realized my issue was the url I was passing to the GetDevDefinedOauthHeader() method. It wasn't getting the right URL passed to it. So instead of baseUrl, I passed the baseUrl + endpointUrl and it worked like a charm.

Hi,

Could please post here an example showing how the jKey is generated ?

Thank you.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,772 views 11 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot