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 Sign up to answer
Community showcase
Published 15 hours ago in Jira

How you can achieve compact and easy-to-maintain workflows in your JIRA( Server)

This approach requires you to have the JIRA administrative rights. The main aim of this article is to help you achieve an organized, easy-to-maintain workflows in your JIRA instance thereby, reducin...

144 views 0 0
Read article

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