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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.