Basic User Authentication => OAuth

codelab expert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 7, 2013

[1]

How can I get the session parameters of the current JIRA web session. I need username and password for authentication purposes (REST).

[2]

I want to switch from basic authentication to oauth. Can somebody give me an code example how to do that! Thank you very much!

This is my current code:

String auth = new String(Base64.encode("username:password"));
    	Client client = Client.create();
    	
    	WebResource webResource = client.resource("http://ubuntu:2990/jira/rest/api/2/search?jql=project=DEMO");
    	
    	ClientResponse response = webResource.header("Authorization", "Basic " + auth).type("application/json").accept("application/json").get(ClientResponse.class);
    	
  	
    	int statusCode = response.getStatus();
    	if (statusCode == 401) {
    	    throw new AuthenticationException("Invalid Username or Password");
    	}

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
codelab expert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 8, 2013

Hi,

here the long way to the solution. A full answer with full source code would be to complex for Atlassian Answer. So you must read the documentation yourself and understand the complete process (e.g. three parts of OAuth dance, Consumer, Service Provider...):

1. Setup your environment ( Step 1 beneath https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+OAuth+authentication )

2. Study the java code in https://developer.atlassian.com/download/attachments/6291692/rest-oauth-client-1.0-sources.jar?api=v2 (extract this jar, it contains 3 files)

I hope this helps!

Geoffrey Rodgers March 10, 2013

Mathias, could I trouble you for some code snippets from your solution? I'm probably looking at having to do something similar.

Thanks!

Adam Barylak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 7, 2013

Mathias, This is answers.atlassian.com, it is not helpful to just post that you resolved it without actually providing a relevant solution. I am now the second person that has come across this answer and would also like code snippets or something to indicate how you were able to resolve your issue. Please let us know. Thanks.

Nitram
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 14, 2014

I am now the third person looking for the code Bro, @Mathias Liefke [primefield software] , could you please show up some code, so that it will help us to solve our problems. Thanks in advance !

codelab expert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 15, 2014

Is this answer ok for you?

2 votes
Matheus Fernandes
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 7, 2013

Hi Mathias,

I was testing this out, but end up finding a public page that should help you through this. :) Please check out the JIRA REST API Example - OAuth authentication. Just remember to create the Application Link in JIRA and to configure the "OAuth Dance" in your code.

I hope this helps!

codelab expert
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 7, 2013

Can you give me an example how I can implement this in java (plugin for JIRA)? Thank you!

TAGS
AUG Leaders

Atlassian Community Events