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?
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
What am I doing wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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:
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Do you have a screenshot of how you implemented this? I don't think I'm doing it right:
What am I doing wrong?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.