I’m working on a project where I need to connect to JIRA using the Python library, but I want to use OAuth2 Bearer token authentication instead of basic auth.
I’ve been looking through the docs for the Python JIRA package but can’t seem to find any examples or documentation about how to set up the JIRA client instance with Bearer token auth. Most examples I see use username/password or API keys.
Has anyone successfully implemented Bearer token authentication with this library? I have a valid OAuth2 token already, I just need to know how to pass it to the JIRA constructor or if there’s a specific method for this type of authentication.
Any code examples or guidance would be really helpful since the official documentation doesn’t seem to cover this authentication method.
Yeah, the Python JIRA library does support Bearer tokens through custom headers, but their docs don’t make it clear.
Just pass the Bearer token using the options parameter:
from jira import JIRA
options = {
'server': 'https://your-jira-instance.com',
'headers': {
'Authorization': f'Bearer {your_oauth2_token}'
}
}
jira = JIRA(options=options)
Or set it after you create the instance:
jira = JIRA('https://your-jira-instance.com')
jira._session.headers.update({'Authorization': f'Bearer {your_token}'})
Honestly though, this auth stuff gets old fast - especially when you need token refresh or multiple services.
I’ve been using Latenode for JIRA integrations instead. It handles OAuth2 natively and you can build workflows without fighting with library quirks. Bearer token auth takes minutes to set up, and it auto-handles token renewal.
Definitely worth a look if you’re doing more than basic scripts: https://latenode.com
i found it easier to just change the session after creating the jira instace. constructor methods can mess up depending on version.
jira = JIRA('https://your-instance.com')
jira._session.headers['authorization'] = f'Bearer {token}'
this has worked for me across various setups.
Hit this exact problem last year migrating our automation scripts. Use the auth parameter with a custom auth class for Bearer tokens.
from jira import JIRA
from requests.auth import AuthBase
class BearerAuth(AuthBase):
def __init__(self, token):
self.token = token
def __call__(self, r):
r.headers['Authorization'] = f'Bearer {self.token}'
return r
jira = JIRA(
server='https://your-jira-instance.com',
auth=BearerAuth(your_oauth2_token)
)
Works way better with the library’s request handling and stays consistent across JIRA versions. When I tried the header approach, token refreshes broke everything. This method handles those edge cases since it runs through the actual auth pipeline.
Hit this exact problem a few months ago switching from basic auth to OAuth2 in our CI pipeline. Use the token parameter directly in the JIRA constructor - it’s barely documented but works great.
from jira import JIRA
jira = JIRA(
server='https://your-domain.atlassian.net',
token_auth=your_bearer_token
)
This beats manually setting headers since the library handles token formatting for you. Way more stable than messing with session headers after setup, especially when tokens expire.
Watch out though - some JIRA Cloud instances need specific scopes on your OAuth2 token depending on what you’re doing. Make sure your token has the right permissions for your API calls or you’ll get weird 403 errors that don’t mention scope problems.