The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

OAuth authentication 2.0(3LO)

Anandhakrishnan
June 22, 2021

I want to authenticate third party application into jira.I got Client Id and Client secret, with this I have generated authorization code.But for 

Exchange authorization code for access token

I used the below code:

String url1="grant_type=authorization_code&client_id=Z6k7drhI5Imruu7UBAXCo4zImlUHUz14&client_secret=9P46D0ZB6vdqaS7Q9IIdBl9q0FLfLJ4RjgV3Kv95F1V8PYBjc6aHvK8GvinV4jRg&code=6Xay_ZrDVhRRa1qW&redirect_uri=http://localhost:8080";
url = new URL("https://auth.atlassian.com/oauth/token");
URLConnection conn = url.openConnection();
HttpURLConnection http=(HttpURLConnection)conn;
((HttpURLConnection) conn).setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-Type", "application/json");
OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
System.out.println("Write1");
writer.write(url1);
System.out.println("Write2");
System.out.println("Response code:" + ((HttpURLConnection) conn).getResponseCode());
System.out.println("Response message:" + ((HttpURLConnection) conn).getResponseMessage());

writer.flush();

BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
System.out.println(line);
sb.append(line);
}

lineV = sb.toString();

writer.close();
reader.close();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

But I got an error like this:

Server returned HTTP response code: 401 for URL: https://auth.atlassian.com/oauth/token

Could you please anyone assist me to resolve this issue?

0 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
FREE
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events