Jira OAuth integration

rest-api

#1

Could anyone can help to provide JIRA API with OAuth authentication from java application…


#2

Hello @janardhanreddy.bored,

If you’re interested with Jira server, you might want to check out this OAuth documentation. There is step by step directions on what and how to do it.

Hope this helps.
Ian


#3

Hi Ian,

Thanks for your reply, I have gone through the link you shared and it says clone the sample code from https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples but it’s not available.

For basic auth we use like below to connect to jira
Client client = null;
Response response = null;
try {
client = ClientBuilder.newClient();
WebTarget webTarget = client.target(url);
response = webTarget.request().header(HttpHeaders.AUTHORIZATION, Base64.getEncoder().encode(username.concat(":").concat(password).getBytes())).accept(MediaType.APPLICATION_JSON).get();
} catch (Exception e) {
e.printStackTrace();
throw new JiraException();
}
return response;

How could we configure for OAuth instead of basic authentication.?


#4

Hi, I was able to clone it just now, it uses mercurial. You can also browse the repository and drill into the projects; I believe you’re more interested with the contents of java folder.

Cheers,
Ian


#5

I’m cloning from GIT repository and getting below error…


#6

The error was caused by using Git in checking out the Mercurial repository. In order to clone this repo, you will be needing to install Mercurial.


#7

Hi Ian,

I’m getting below error could you please help what might went wrong…

Creating default properties file: config.properties com.google.api.client.http.HttpResponseException: 400 Bad Request oauth_problem=timestamp_refused&oauth_acceptable_timestamps=1543578273941-1543578873941 at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1070) at com.google.api.client.auth.oauth.AbstractOAuthGetToken.execute(AbstractOAuthGetToken.java:73) at com.soctronics.ims.atlasian.oauth.JiraOAuthClient.getAndAuthorizeTemporaryToken(JiraOAuthClient.java:37) at com.soctronics.ims.atlasian.oauth.OAuthClient.handleGetRequestTokenAction(OAuthClient.java:69) at com.soctronics.ims.atlasian.oauth.OAuthClient.execute(OAuthClient.java:51) at com.soctronics.ims.atlasian.oauth.ClientMain.main(ClientMain.java:18)


#8

Hi Ian,

Thanks for your prompt help. It’s actually worked out.

Here i have another question, that by using JIRA OAuth with accessToken for API /rest/api/2/issue/{issueIdOrKey}/comment when any user comments it’s saving commented by (xxx) with same user for all. How can it be solved?

Actually in Basic authentication we pass username and password to the request but in OAuth how can send username?

Please help to move further… Thanks.

Regards
Janardhan


#9

You’re welcome, @janardhanreddy.bored. With what you’re experiencing, I am assuming the username of the user who did the OAuth dance is being the requestor all the time. This is as expected since only that resource owner is authenticated and you’re using their tokens. To get through this, each user should go through the authentication process (OAuth dance), keep their unique tokens, and use those when doing authenticated requests.

Cheers,
Ian


#10

Thanks Ian. I got your solution and it means allot to me…

I’m facing other issue that I have created a new standalone app for communicating to JIRA to get requestTokens and getting proper response. and the same source code & dependencies has been copied to my existing project and trying to get requestToken but getting below error
401 Unauthorized
oauth_problem=signature_invalid&oauth_signature=p3zWRGn94%2FokkTaMVRwIqTxKjim%2BzoKsfOm6sV%2B1EqrVOzRkHtwu69%2BmunAZsnMd8wwPPUSKuyY3T7iVXQbppukJ1TFuZZOYqntftU1pljVES2rdcQi5IMu1Wh%2BuN5ZgOEsnUBx4b0YQuYtpdfgtbjT7cRvhbd%2FMV97OUN6F%2BUw%3D&oauth_signature_base_string=POST%26https%253A%252F%252Finvjira.invecas.com%253A8443%252Fplugins%252Fservlet%252Foauth%252Frequest-token%26oauth_callback%253Doob%2526oauth_consumer_key%253Dcss_local%2526oauth_nonce%253D6080d8173ff48d0c%2526oauth_signature_method%253DRSA-SHA1%2526oauth_timestamp%253D1544691450&oauth_signature_method=RSA-SHA1

Could you please suggest me what am’i doing wrong…

Thanks
Janardhan


#11

I have not encountered that error yet, but you might want to check this Knowledge Base article to shed some light. You might have overlooked something when you copied from one app to the other.