Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to deal with "Failed to parse Connect Session Auth Token"?

Sidrit Reka
Contributor
June 25, 2018

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?

1 answer

1 vote
Valery Lebedz July 26, 2018

Have you found an answer to this issue? 

Sidrit Reka
Contributor
July 27, 2018

Hi Valery,

Apparently the Jira documentation about this was wrong. We shouldn't use Bearer authentication, but instead try to authenticate with OAuth1 standart.

Like # people like this
Deepak Kumar
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 2, 2018

@Sidrit Reka Can you please elaborate how to authenticate with OAuth1 standard?

Like # people like this
Admin
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 18, 2019

@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 :)

Like # people like this
Chakresh Tiwari March 31, 2020

Hi @Deepak Kumar  

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.

Theodore Ravindranath
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
June 19, 2024

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

`

Like Gautam Singh likes this

Suggest an answer

Log in or Sign up to answer