Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jira token_auth not working #1897

Open
2 of 4 tasks
MateusZ36 opened this issue Sep 18, 2024 · 3 comments
Open
2 of 4 tasks

Jira token_auth not working #1897

MateusZ36 opened this issue Sep 18, 2024 · 3 comments

Comments

@MateusZ36
Copy link

MateusZ36 commented Sep 18, 2024

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?

  • 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?

  • 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

@dimitarOnGithub
Copy link

Can you please try:

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

and see if that works?

@MateusZ36
Copy link
Author

MateusZ36 commented Sep 19, 2024

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants