I am trying to complete authentication flow with Jira. After following the steps in this link:
https://developer.atlassian.com/server/jira/platform/oauth/ , I am able to get the access token. The requests I do are:
1)BaseUrl/plugins/servlet/oauth/request-token
2)After that I am prompted to the login page in my browser and I successfully grant access.
The url is BaseUrl/plugins/servlet/oauth/authorize?oauth_token={token in the first step}
3)And I get the access token with this request:
BaseUrl/plugins/servlet/oauth/access-token
Finally I try to make a request to get my issues and I pass the access token to the authorization header like this:
Authorization: Bearer {accesstoken}
And I get 403 error code with the message "{"error": "Failed to parse Connect Session Auth Token"}"
Can someone guide me to a solution for this?
Hi Valery,
Apparently the Jira documentation about this was wrong. We shouldn't use Bearer authentication, but instead try to authenticate with OAuth1 standart.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Sidrit Reka Can you please elaborate how to authenticate with OAuth1 standard?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Deepak Kumar In Python;
You can use HTTPBasicAuth to get access with JIRA API;
Sample code;
# Call JIRA API with HTTPBasicAuth
import json
import requests
from requests.auth import HTTPBasicAuth
JIRA_EMAIL = "****"
JIRA_TOKEN = "****"
BASE_URL = "https://****.atlassian.net"
API_URL = "/rest/api/3/serverInfo"
API_URL = BASE_URL+API_URL
BASIC_AUTH = HTTPBasicAuth(JIRA_EMAIL, JIRA_TOKEN)
HEADERS = {'Content-Type' : 'application/json;charset=iso-8859-1'}
response = requests.get(
API_URL,
headers=HEADERS,
auth=BASIC_AUTH
)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
Thanks :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If I am trying the same solution in java then if our app is installed in some other person Jira account and if he is calling then how to pass that token dynamically. Because this is fixed for a particular user.
Any Suggestion. How to do that in java.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Very late reply.. however it may be useful for others:
Adapting Admin's Python answer to Java with OkHttp3 library:
`
import okhttp3.Credentials;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class OkHttpBasicAuthExample {
public static void main(String[] args) {
try {
String apiUrl = "/rest/api/3/serverInfo"
String baseUrl = "https://****.atlassian.net";
String username = "your-jira-mail-id";
String password = "your-jira-personal-token";
OkHttpClient client = new OkHttpClient();
String credential = Credentials.basic(username, password);
Request request = new Request.Builder()
.url(baseUrl + specificApi)
.header("Authorization", credential)
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println("Response Code: " + response.code());
System.out.println("Response: " + response.body().string());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
`
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.