Hi all,
I currently use basic authentication with password as below:
```
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI jiraServerUri = baseUrl.toURI();
restClient = factory.createWithBasicHttpAuthentication(jiraServerUri, config.getUsername(), config.getPassword());
```
How do I use a personal access token (PAT) in jira-rest-java-client ? What's the correct method to get a restClient with PAT ?
Is that correct to replace username with email address, and password with PAT with the same createWithBasicHttpAuthentication call ?
Thanks.
That does sound correct.
Username = email address
Password = PAT
and use Basic Authentication
Thank you for the reply.
It seems to be this must use Basic Authentication (based on https://bitbucket.org/atlassian/jira-rest-java-client/src/ecc435281cfd046f155996025fcd418033a7a13f/core/src/main/java/com/atlassian/jira/rest/client/auth/BasicHttpAuthenticationHandler.java#lines-44), however, we're moving to use PAT and stop using basic authentication for our Jira.
Is there a way to just use bearer authentication with JRJC ?
e.g. in cURL I can get access to Jira with:
curl -H "Authorization: Bearer <MyToken>" https://{JiraBaseUrl}/rest/api/content
Is that possible to achieve the same goal this in JRJC ?
==================================================================
Edit: it seems that I must create a AuthenticationHandler as:
public class BearerHttpAuthenticationHandler implements AuthenticationHandler {
private static final String AUTHORIZATION_HEADER = "Authorization";
private final String token;
public BearerHttpAuthenticationHandler(final String token) {
this.token = token;
}
@Override
public void configure(Builder builder) {
builder.setHeader(AUTHORIZATION_HEADER, "Bearer " + token);
}
}
and create with this authentication handler like:
BearerHttpAuthenticationHandler handler = new BearerHttpAuthenticationHandler(config.getToken());
JiraRestClient restClient= factory.createWithAuthenticationHandler(jiraServerUri, handler);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
AuthenticationHandler works!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is jrjc with bearer authentication available in maven repository?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What is the use of this part-
public void configure(Builder builder) {
builder.setHeader(AUTHORIZATION_HEADER, "Bearer " + token);
}
And I am facing difficulty in creating the handler by this method.
BearerHttpAuthenticationHandler handler = new BearerHttpAuthenticationHandler(config.getToken());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Chao Wang
This helps!
Created:
public class BearerHttpAuthenticationHandler implements AuthenticationHandler {
private static final String AUTHORIZATION_HEADER = "Authorization";
private final String token;
public BearerHttpAuthenticationHandler(final String token) {
this.token = token;
}
@Override
public void configure(Builder builder) {
builder.setHeader(AUTHORIZATION_HEADER, "Bearer " + token);
}
}
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
BearerHttpAuthenticationHandler handler = new BearerHttpAuthenticationHandler(<PAT>);
JiraRestClient restClient= factory.create(getJiraUri(), handler);
I just have to use factory.create(uri, handler) instead of
factory.createWithAuthenticationHandler(jiraServerUri, handler);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.