Naasheer
Naasheer

Reputation: 138

How to get OAuth token for jira

Jira Api supports Basis Authorization and OAth Authorization. I tried with Basic Authorization, It works fine. Now I'm trying with OAuth Authorization but I can not get the access token.

  1. I've created an Application Link.
  2. This is my base url : "esbjira.atlassian.net"
  3. Callback URL is None, I didn't give any value.
  4. Then I downloaded the two jar files and put them into a folder then I navigated to the folder in terminal and ran the following command in terminal. java -jar rest-oauth-client-1.0.one-jar.jar requestToken https://esbjira.atlassian.net

This is the Api documentation link that I'm refering : https://developer.atlassian.com/jiradev/api-reference/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-oauth-authentication

Can anyone help me to find the access token?Am I missing anything?

Upvotes: 8

Views: 8041

Answers (1)

Harshad Holkar
Harshad Holkar

Reputation: 541

D:\OAuth Jars>java -jar rest-oauth-client-1.0.one-jar.jar requestToken "Your Jira base url"

Once you execute the above command you will get the Token, Token secret and Retrieved request token.

Token is iJKs7Sq4nI3tK0bTqBYSNNOt9rkwrKK9
Token secret is qimK5FibcAKD5ACbF2aKEPpiBWltgwET
Retrieved request token. go to http://bmh1060149:8080/plugins/servlet/oauth/authorize?oauth_token=iJKs7Sq4nI3tK0bTqBYSNNOt9rkwrKK9

Then you have to invoke the Retrieved request token url through the browser to get the verification code. It will ask you to allow or deny. If you click on allow it will give you verification code.

Then you can use Token, Token secret, your base url and verification code to get the access token.

D:\OAuth Jars>java -jar rest-oauth-client-1.0.one-jar.jar accessToken "Your Jira base url" "iJKs7Sq4nI3tK0bTqBYSNNOt9rkwrKK9" "qimK5FibcAKD5ACbF2aKEPpiBWltgwET" "toYvZB"
Access token is : zGBqUzmwobyS0GFXrJMIs18lsAUd51Wb

Once you get the access token you can fetch the data from whatever url you will pass to it.

D:\OAuth Jars>java -jar rest-oauth-client-1.0.one-jar.jar request "zGBqUzmwobyS0GFXrJMIs18lsAUd51Wb" "Your Jira base url/rest/api/2/issue/NWFM-4"

One more thing if from the above steps you are not able to get the data then you have to set the consumer key as "hardcoded-consumer" because for the that was the problem that was occuring. So while setting up an application link in Jira give consumer key as "hardcoded-consumer".

public key will be :

MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAxZDzGUGk6rElyPm0iOua0lWg84nOlhQN1gmTFTIu5WFyQFHZF6OA4HX7xATttQZ6N21yKMakuNdRvEudyN/coUqe89r3Ae+rkEIn4tCxGpJWX205xVF3Cgsn8ICj6dLUFQPiWXouoZ7HG0sPKhCLXXOvUXmekivtyx4bxVFD9Zy4SQ7IHTx0V0pZYGc6r1gF0LqRmGVQDaQSbivigH4mlVwoAO9Tfccf+V00hYuSvntU+B1ZygMw2rAFLezJmnftTxPuehqWu9xS5NVsPsWgBL7LOi3oY8lhzOYjbMKDWM6zUtpOmWJA52cVJW6zwxCxE28/592IARxlJcq14tjwYwIDAQAB

or you can generate public key via openssl software.

Hope this helps

Upvotes: 0

Related Questions