Hello,
I am encountering a persistent issue with accessing the Jira Cloud API using OAuth 2.0 token authentication. Despite following the documentation and ensuring that all required scopes and configurations are set correctly, I am continuously receiving a 401 Unauthorized error. Below are the detailed steps I have taken and the responses received:
read:jira-user
and read:jira-work
./rest/api/3/myself
and a specific issue endpoint /rest/api/3/issue/DEMO-1
# OAuth2 configuration
client_id = 'client_id'
client_secret = 'client_secret'
authorization_base_url = 'https://auth.atlassian.com/authorize'
token_url = 'https://auth.atlassian.com/oauth/token'
redirect_uri = 'https://demo'
# Initialize OAuth2Session
oauth = OAuth2Session(client_id, redirect_uri=redirect_uri, scope="read:jira-user read:jira-work")
# Direct user to authorization URL
authorization_url, state = oauth.authorization_url(authorization_base_url)
# Fetch the access token
token = oauth.fetch_token(token_url, authorization_response=redirect_response, client_secret=client_secret)
# Define API URL
jira_api_url = 'https://demo.atlassian.net/rest/api/3/issue/demo-1'
# Set headers
headers = {
'Authorization': f'Bearer {token["access_token"]}',
'Accept': 'application/json'
}
# Make API request
response = requests.get(jira_api_url, headers=headers)
https://demo.atlassian.net/rest/api/3/issue/DEMO-1
401 - Client must be authenticated to access this resource.
{
'Date': 'Tue, 28 May 2024 09:06:48 GMT',
'Content-Type': 'application/json;charset=UTF-8',
'Content-Length': '53',
'Server': 'AtlassianEdge',
'Timing-Allow-Origin': '*',
'X-Arequestid': 'af12f852e377c6b484923a965f75ecdd',
'Set-Cookie': 'atlassian.xsrf.token=XXX; Path=/; SameSite=None; Secure',
'Cache-Control': 'no-cache, no-store, no-transform',
'Www-Authenticate': 'OAuth realm="https%3A%2F%2Fdemo.atlassian.net", OAuth realm="https%3A%2F%2Fdemo.atlassian.net"',
'X-Content-Type-Options': 'nosniff',
'X-Xss-Protection': '1; mode=block',
'Atl-Traceid': 'XX',
'Strict-Transport-Security': 'max-age=63072000; includeSubDomains; preload',
'Report-To': '{"endpoints": [{"url": "https://dz8aopenkvv6s.cloudfront.net"}], "group": "endpoint-1", "include_subdomains": true, "max_age": 600}',
'Nel': '{"failure_fraction": 0.001, "include_subdomains": true, "max_age": 600, "report_to": "endpoint-1"}'
}
Hi @Kürşad ÇEVİK . Were you referencing these docs when trying to implement OAuth2? https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/
If so, check out the section 3. Make calls to the API using the access token - notice that you'll need to use the `cloudId` and place that into the request URL to look something like this:
https://api.atlassian.com/ex/jira/{cloudid}/rest/api/3/issue/DEMO-1
I think I opened the topic in the wrong category. I apologize for that.
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.