It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Jira REST api getting 403 Forbidden Basic Authentication Edited

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

0 votes
Answer accepted

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();
}
}

}

0 votes

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

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you