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 client accepts auth options inflexibly #1772

Open
leifwalsh opened this issue Dec 7, 2023 · 2 comments
Open

JIRA client accepts auth options inflexibly #1772

leifwalsh opened this issue Dec 7, 2023 · 2 comments
Labels

Comments

@leifwalsh
Copy link

Problem trying to solve

At work we configure lots of python libraries to do authentication with our internal SSO system, and to do so we've got our own subclasses of requests.auth.AuthBase that do mostly well known things like OAuth and Kerberos, but also handle retries and fallback mechanisms in ways that are important to us.

Anyway, there seems to be no way to pass either a pre-configured requests.Session, or a subclass of requests.auth.AuthBase in to JIRA's constructor. It accepts the parameters needed to construct a variety of AuthBase derivatives, but won't let me say "trust me" and pass an Auth object.

Possible solution(s)

Basically, dependency injection: change JIRA to accept either a Session or an Auth object and use it, instead of it constructing its own. Many (not all, sadly) other libraries let you pass in a Session, but I think actually the way requests is designed it's better to pass in an Auth object, but most people don't.

Alternatives

For now I can subclass it and have my constructor do something like

super().__init__(validate=False, get_server_info=False, *args, **kwargs)
self._session.auth = my_auth
if validate:
    ...   # steal code from JIRA.__init__
if get_server_info:
    ...   # steal code from JIRA.__init__

but I don't love monkeying with self._session nor that code duplication.

Additional Context

I know you're busy and have asked for help with CI. If I can find someone who has some time to propose a PR, we can do that, I just wanted to float the idea as an issue first to see if you hate it.

@adehad
Copy link
Collaborator

adehad commented Dec 25, 2023

From my perspective I like the idea. Currently the Jira client init method is bloated with auth stuff. I think it would be great to have an auth module and then dedicated AuthBase subclasses. Perhaps a method like a generic get_jira_auth() that has all that complexity of the current implementation can be used to preserve backwards compatibility.

Some points to consider:

  1. If we want to move to httpx (my current preference for an Async Jira client) how would we want to handle the auth class (if the classes are incompatible, I haven't really checked). But might be worth considering at this stage.

@adehad adehad added help wanted feature good first issue New contributors welcome ! labels Dec 25, 2023
@leifwalsh
Copy link
Author

httpx doesn't support request style auth classes, because the callback may need to be async. But their customization mechanism is pretty similar: https://www.python-httpx.org/advanced/#customizing-authentication

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

No branches or pull requests

2 participants