Jira authentication method Bearer token is not working

Tex
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!
February 3, 2022

Hi all

Since Jira changed the authentication type from Basic to Bearer token,  I am unable to access it properly 

And a quick test with bearer token in header as

curl -s -X GET -H "Content-Type: application/json" -H "Authorization: Bearer AbC12EdEtc." -v https://[example].atlassian.net/rest/api/2/issue/TWS-4 

returns error as

{"errorMessages":["Issue does not exist or you do not have permission to see it."],"errors":{}}%   

but test with –user as below

curl -s -X GET -H "Content-Type: application/json" "https://[example].atlassian.net/rest/api/2/issue/TWS-4 " --user info@myemail.com:AbC12EdEtc.

returns success with details of the issue.

I really do not understand why the first one is not working because that is how to programmatically code it in spring resttemplate. I fail to find a way to code the latter one in my java code.

Can you help me with some ideas?

1 answer

1 accepted

1 vote
Answer accepted
Pramodh M
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 3, 2022

Hi @Tex 

Welcome to the Community!!

Here's a sample on how to create a bearer token and authenticate to Atlassian provided APIs

# This code sample uses the 'requests' library:
# http://docs.python-requests.org
import requests
from requests.auth import HTTPBasicAuth
import json
import base64

url = "https://your-site.atlassian.net/rest/api/3/issue/WSP-70"


credentials = "Basic " + base64.b64encode("your-email:your-token".encode("ascii")).decode("ascii")

# Here you will have Bearer token
print(credentials)

headers = {
"Accept": "application/json",
"Authorization": credentials
}

response = requests.request(
"GET",
url,
headers=headers
)

print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))

Let me know if you have any doubts

Thanks,
Pramodh

Tex
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!
February 3, 2022

Thanks a lot Pramodh. it works that way.

It seems that the announcement has confused me by saying "Basic authentication 

will no longer work" led me to use "Authorization: Bearer" instead but now with Basic it is also working instead I had to use email and generated token

 

many many thanks again

Like Alex Johnson likes this
Stephen Barrett
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!
February 6, 2024

Hi Pramodh,

 

what you have described is basic authentication using a PAT in lace of a password.

Thsi is NOT Bearer authentication, whcih would be to set the Authorisation header to "Bearer <your token>" as described in atlassian documentation.

I have been unable to use a PAT against any REST endpoint using Bearer authentication as decribed in Atlassian documentation. I get the same behaviour as Tex.

Does Atlassian support Bearer, or should PATs be used in Basic authentication only?

thanks,

s.

 

Like Rasmus Norup likes this
Rasmus Norup April 5, 2024

As far as I can tell, the documentation is wrong.

I have tried many times to use the Bearer token, never been able to get it to work. But every single time it works if "Bearer {token}" is replaced with "Basic {encoded email:PAT}.

Did they remove support for Bearer token and just forget to tell the guys that writes the docs?

Please let me know if you find something out

 

@Pramodh M You do realize that your solution does not involve a bearer token, right? You are using basic auth with a PAT. Just calling something a bearer token does not make it one.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events