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: 

Jira REST api getting 403 Forbidden Basic Authentication

roliveiras1994
December 5, 2018

I am trying to do a basic auth to Jira, but i keep receiving the error 403 forbidden.

My code is : 

package br.com.indra.jiraauto.authentication;
import static java.lang.System.out;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
public class authentication
{

public static void main(String[] args) {
//code
CredentialsProvider provider = new BasicCredentialsProvider();
UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("username", "password");
provider.setCredentials(AuthScope.ANY, credentials);
HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();

HttpResponse response;
try {
response = client.execute(new HttpGet("https://localhost:8080/rest/api/2/issue/project-1"));
int statusCode = response.getStatusLine().getStatusCode();
out.println("Response Code :"+ statusCode);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}
}

 

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
roliveiras1994
December 7, 2018

thanks , but I've made it work with this code:

 

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class getIssue {

public static void main(String[] args) {

try {
HttpResponse<String> response = Unirest.get("<jiralink>")
.header("Content-Type", "application/json")
.header("Authorization", "Basic <64login:pass>")

.header("cache-control", "no-cache")
.asString();
System.out.println(response.getCode());
System.out.println(response.getBody());
} catch (UnirestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}

4 votes
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 6, 2018

Hello Rafael,

There are a couple things to check to ensure your account is working as expected.

  1. Has CAPTCHA been triggered for the user, preventing them from authenticating?
    1. Complete the following to reset CAPTCHA:
      1. Click on the Gear icon in the upper right of JIRA
      2. Select User Management
      3. Find the right user
      4. Click on the Reset Failed Login Countlink in the Login Details column.
  2. Can you access the URL within a browser and get a valid response?

Please let us know if if these help or if you’re still getting a 403 response.

Regards,
Stephen Sifers

Thomas Gavin
May 8, 2020

Thanks @Stephen Sifers  You're no 1 helped me out with a 403 issue :-)

Loïc Dewerchin
Contributor
October 27, 2021

Captcha reset was the reason for me too, thanks!

TAGS
AUG Leaders

Atlassian Community Events