I have gone through documetation https://developer.atlassian.com/server/jira/platform/oauth/
and java sample code from https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples.
I tried to implement Oauth as below.
//For Basic authentication
public JiraRestClient getJiraClient() throws URISyntaxException {
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
return factory.createWithBasicHttpAuthentication(new URI(jiraBaseURL), jiraUser, jiraPassword); // this code working fine, I can get issue details
}
//For Oauth authentication
public JiraRestClient getOAuthJiraClient() throws URISyntaxException {
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
return factory.create(new URI(jiraBaseURL), getAuthenticationHandler());// what exactly we need to pass here in second param?
}
private AuthenticationHandler getAuthenticationHandler() {
return new AuthenticationHandler() {
@Override
public void configure(Request.Builder builder) {
builder.setHeader("Authorization", "Bearer " + accessToken); // is this correct?
}
};
}
I am getting below errors.
1. for get Request
"status": 500,
"error": "Internal Server Error",
"exception": "java.util.concurrent.ExecutionException",
"message": "RestClientException{statusCode=Optional.of(401), errorCollections=[ErrorCollection{status=401, errors={}, errorMessages=[You do not have the permission to see the specified issue., Login Required]}]}",
2. for post request
"status": 500,
"error": "Internal Server Error",
"exception": "com.atlassian.jira.rest.client.api.RestClientException",
"message": "[ErrorCollection{status=400, errors={}, errorMessages=[The value 'XXXX' does not exist for the field 'project'.]}]",
What is causing this problem?
how to implement configure() method of AuthenticationHandler?
I am using jira-rest-java-client-core 4.0.0.