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?

4 answers

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 # people like 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.

Like Alexis likes this
sai_reddy
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!
August 21, 2024

Hey is there any update.
Did anyone be able to use "Bearer {token}" instead of "Basic {encoded email:PAT}".

 

Please let me know if anyone found something

Rodney Estrada
Contributor
October 3, 2024

: (

1 vote
Alexis
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!
August 21, 2024

I can confirm Atlassian documentation is plain wrong : a PAT send as a standard Bearer Token is *not accepted*, I got a 403 Forbiden response : {"error": "Failed to parse Connect Session Auth Token"}

but is accepted as the password field of a Basic Auth scheme..

It's a shame.. how is this behavior still wrongly documented in 08/2024 ?!

..but at least I figure a way to connect to this API, thanks a lot !

 

so don't blindly follow this documentation : Using Personal Access Tokens | Atlassian Support | Atlassian Documentation

0 votes
Christel Gray
Contributor
December 18, 2024

I've been dealing with the same issue for awhile now and thought Kale had the answer, but I'm having issues implementing it.

Do I need to Base64 encode the API to use it in the header for Authorization?

Does it need "Basic" before the Base64 encoded key?

Here is how I did it:

2024-12-18_11-16-08.png What am I doing wrong?

0 votes
Kale Masters
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 5, 2024

After much frustration, I think I have finally found the solution!

Aside from the user API tokens (Personal Access Tokens), there's another type of API key for Atlassian Admin APIs Manage an organization with the admin APIs | Atlassian Support.

If you are an org admin, you can go to:

  • Security > Monitoring > User API tokens = these are the normal personal access tokens, which allow access to many APIs but may show 401 errors for other admin level ones.
  • Settings > API Keys = these API keys allow you to manage your organization via the Atlassian Admin APIs. You can update organization settings and manage user accounts by making requests to HTTP endpoints. 

When testing GET https://api.atlassian.com/users/{{accountID}}/manage/profile with my PAT it would fail with a 401 error, but when using the Admin API Key it would work for me.

Christel Gray
Contributor
December 18, 2024

Do you have a screenshot of how you implemented this? I don't think I'm doing it right:

2024-12-18_11-16-08.png What am I doing wrong?

Suggest an answer

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

Atlassian Community Events