Skip to content

Commit 9c087f4

Browse files
committed
feat: Add bearer auth with JIRA Personal Access Token
1 parent 85fe429 commit 9c087f4

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ Use it as a last-resort only, when other means of exclusion do not suit your cas
105105

106106
### Authentication
107107

108-
It is possible to either use the username/password combination or to login via the browser passing in `--cookie <JSESSIONID>`. This logins via the browser and is useful in scenarios where Kerberos authentication is required.
108+
It is possible to either use:
109+
* the username/password combination
110+
* to login via a token passing in `--bearer <BEARER TOKEN>`. This allows to use a Personal Access Token generated in your JIRA profile (https://confluence.atlassian.com/enterprise/using-personal-access-tokens-1026032365.html)
111+
* to login via the browser passing in `--cookie <JSESSIONID>`. This logins via the browser and is useful in scenarios where Kerberos authentication is required.
109112

110113
If you are using Atlassian Cloud, use your API token instead of your account password. You can generate one with the following steps:
111114

jira-dependency-graph.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ def get(self, uri, params={}):
3535
headers = {'Content-Type' : 'application/json'}
3636
url = self.url + uri
3737

38-
if isinstance(self.auth, str):
39-
return requests.get(url, params=params, cookies={'JSESSIONID': self.auth}, headers=headers, verify=self.no_verify_ssl)
38+
if isinstance(self.auth, dict):
39+
headers_with_auth = headers.copy()
40+
headers_with_auth.update(self.auth)
41+
return requests.get(url, params=params, headers=headers_with_auth, verify=(not self.no_verify_ssl))
4042
else:
4143
return requests.get(url, params=params, auth=self.auth, headers=headers, verify=(not self.no_verify_ssl))
4244

@@ -235,6 +237,7 @@ def parse_args():
235237
parser.add_argument('-u', '--user', dest='user', default=None, help='Username to access JIRA')
236238
parser.add_argument('-p', '--password', dest='password', default=None, help='Password to access JIRA')
237239
parser.add_argument('-c', '--cookie', dest='cookie', default=None, help='JSESSIONID session cookie value')
240+
parser.add_argument('-b', '--bearer', dest='bearer', default=None, help='Bearer Token (Personal Access Token)')
238241
parser.add_argument('-N', '--no-auth', dest='no_auth', action='store_true', default=False, help='Use no authentication')
239242
parser.add_argument('-j', '--jira', dest='jira_url', default='http://jira.example.com', help='JIRA Base URL (with protocol)')
240243
parser.add_argument('-f', '--file', dest='image_file', default='issue_graph.png', help='Filename to write image to')
@@ -267,9 +270,12 @@ def append_unique(acc, item):
267270
def main():
268271
options = parse_args()
269272

270-
if options.cookie is not None:
273+
if options.bearer is not None:
274+
# Generate JIRA Personal Access Token and use --bearer=ABCDEF012345 commandline argument
275+
auth = {'Authorization': 'Bearer ' + options.bearer}
276+
elif options.cookie is not None:
271277
# Log in with browser and use --cookie=ABCDEF012345 commandline argument
272-
auth = options.cookie
278+
auth = {'JSESSIONID': options.cookie}
273279
elif options.no_auth is True:
274280
# Don't use authentication when it's not needed
275281
auth = None

0 commit comments

Comments
 (0)