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

Add option to add custom headers to Jira Client (or enable token Bearer auth at least) #989

Closed
skaiaa opened this issue Dec 10, 2020 · 5 comments

Comments

@skaiaa
Copy link
Contributor

skaiaa commented Dec 10, 2020

I have to login to Jira using a Token with header like this "authetication":"Bearer <TOKEN>". There is no option to add headers manually and token auth is not one of the provided ways to authenticate. This blocks me from using a client at all, because I cannot authenticate properly.
Please, consider adding an option for custom headers. Is there a workaround which would make token bearer authentication work?

@skaiaa
Copy link
Contributor Author

skaiaa commented Dec 10, 2020

I've forked the repo and added token auth option: https://github.com/skaiaa/jira/blob/master/jira/client.py

@danielflira
Copy link

danielflira commented Dec 10, 2020

Apparently on JIRA constructor it makes a copy of JIRA.DEFAULT_OPTIONS dictionary then it uses options parameter to update internal options, try something like:

headers = JIRA.DEFAULT_OPTIONS["headers"].copy()
headers["my-header"] = "my value"
jira = JIRA(options={"headers": headers})

@skaiaa
Copy link
Contributor Author

skaiaa commented Dec 10, 2020

Thanks! It worked for me :) I've created PR with token auth added, so maybe it'll be useful and more clean fix for the future. #991

@skaiaa skaiaa closed this as completed Dec 10, 2020
@oaustegard
Copy link

To be entirely clear to anyone looking to use a Personal Access token - @danielflira's excellent workaround would look like this:

host = "YOUR_JIRA_URL"
pat = "YOUR_PERSONAL_ACCESS_TOKEN"

headers = JIRA.DEFAULT_OPTIONS["headers"].copy()
headers["Authorization"] = f"Bearer {pat}"
jira=JIRA(server=host, options={"headers": headers})

@prigio
Copy link

prigio commented Apr 13, 2021

A nice solution, but does not allow to use client-side TLS certificates.

This is the (terrible) hack which did it for me

class JIRA_With_Token_Auth(jira.JIRA):
    """This is a HORRIBLE HACK to cope with the lack of real support for Personal Access Token authentication
    """
    def _create_http_basic_session(self, username, password, timeout=None):
        verify = self._options['verify']
        self._session = jira.client.ResilientSession(timeout=timeout)
        self._session.verify = verify
        # if they are empty, leave _session.auth=None
        if username and password:
            self._session.auth = (username, password)
        self._session.cert = self._options['client_cert']


j = JIRA_With_Token_Auth(server, basic_auth=(None,None), options=dict(client_cert=cert))

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

4 participants