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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

72 views 1 0
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