jira icon indicating copy to clipboard operation
jira copied to clipboard

Jira token_auth not working

Open MateusZ36 opened this issue 1 year ago • 6 comments

Bug summary

I tried doing something like this:

jira_instance = JIRA(
    server='https://XXX.atlassian.net/',
    token_auth=access_token,
)

I'm getting the folowing error:

raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 401 url: https://XXX.atlassian.net/rest/api/2/serverInfo
	text: Client must be authenticated to access this resource.

the access token is valid, normal requests to te API works.

Is there an existing issue for this?

  • [X] I have searched the existing issues

Jira Instance type

Jira Cloud (Hosted by Atlassian)

Jira instance version

No response

jira-python version

3.8.0

Python Interpreter version

3.12

Which operating systems have you used?

  • [X] Linux
  • [ ] macOS
  • [ ] Windows

Reproduction steps

# 1. Get an access token of your account

# 2. Try to use it to create an instance of JIRA
jira_instance = JIRA(
    server='https://XXX.atlassian.net/',
    token_auth=access_token,
)
# 3. "Client must be authenticated to access this resource." error shows up

Stack trace

Traceback (most recent call last):
  File "/path/to/your/project/jiratessts.py", line 20, in <module>
    jira_instance = JIRA(
                    ^^^^^
  File "/path/to/your/project/.venv/lib/python3.12/site-packages/jira/client.py", line 660, in __init__
    si = self.server_info()
         ^^^^^^^^^^^^^^^^^^
  File "/path/to/your/project/.venv/lib/python3.12/site-packages/jira/client.py", line 3599, in server_info
    j = self._get_json("serverInfo")
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/your/project/.venv/lib/python3.12/site-packages/jira/client.py", line 4358, in _get_json
    else self._session.get(url, params=params)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/your/project/.venv/lib/python3.12/site-packages/requests/sessions.py", line 602, in get
    return self.request("GET", url, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/your/project/.venv/lib/python3.12/site-packages/jira/resilientsession.py", line 247, in request
    elif raise_on_error(response, **processed_kwargs):
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/your/project/.venv/lib/python3.12/site-packages/jira/resilientsession.py", line 72, in raise_on_error
    raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 401 url: https://XXX.atlassian.net/rest/api/2/serverInfo
    text: Client must be authenticated to access this resource.
    
    response headers = {'Date': 'Wed, 18 Sep 2024 14:43:42 GMT', 'Content-Type': 'text/html;charset=UTF-8', 'Content-Length': '53', 'Server': 'AtlassianEdge', ...}
    response text = Client must be authenticated to access this resource.

Expected behaviour

It should authenticate and let me use the instance.

Additional Context

No response

MateusZ36 avatar Sep 18 '24 14:09 MateusZ36

Can you please try:

jira_instance = JIRA(
    server='https://XXX.atlassian.net/',
    basic_auth=(<username/email here>, <token here>),
)

and see if that works?

dimitarOnGithub avatar Sep 19 '24 08:09 dimitarOnGithub

This way it doesn't give any error when instancing but later when trying to, for example: jira_instance.myself() or jira_instance.issue() it does

I'm getting the token trough OAuth 2.0 (3LO) apps, idk if this helps

MateusZ36 avatar Sep 19 '24 12:09 MateusZ36

Update: I was able to create an instance using this:

JIRA(
    server=f"https://api.atlassian.com/ex/jira/{cloud_id}",
    token_auth=access_token,
    validate=False
)

there are a few enpoints, like myself() that doesnt work because of the base URL but I can manage that

MateusZ36 avatar Sep 23 '24 14:09 MateusZ36

Hi, I am having a similar issues with my companys jira server using token without verification

This is my code.

options = {'server':'https://abc', 'verify':False} jira = JIRA(options, token_auth="xyz")

For some unknown reason, it already leads to a 404 error complaining about the non-existence of https://abc/api/2/serverInfo where abc is the server address of my own company.

What should I do with the endpoints provided by the admin of the jira server of my company? I am provided

abc

and

abc/jira/rest/api/2/myself/

I tried both but "rest/api/2/serverInfo" is added to both addresses and then a 404 error.

wailoktam avatar Feb 03 '25 05:02 wailoktam

I ask the admin about the cloudid solution. But we are using jira datacenter and so he does not have one. Any idea on a solution for token auth plus jira data center?

wailoktam avatar Feb 05 '25 00:02 wailoktam

I thought jira datacenter is 90% the same as jira server can someone at atlassian confirm that @skumar36-atlassian

studioj avatar Apr 01 '25 21:04 studioj