Skip to content

Commit 6350fb7

Browse files
authored
Merge pull request #49 from blesenechal/feat/auth-oauth
Add bearer auth with JIRA Personal Access Token
2 parents 24d8b5c + 9c087f4 commit 6350fb7

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

@@ -238,6 +240,7 @@ def parse_args():
238240
parser.add_argument('-u', '--user', dest='user', default=None, help='Username to access JIRA')
239241
parser.add_argument('-p', '--password', dest='password', default=None, help='Password to access JIRA')
240242
parser.add_argument('-c', '--cookie', dest='cookie', default=None, help='JSESSIONID session cookie value')
243+
parser.add_argument('-b', '--bearer', dest='bearer', default=None, help='Bearer Token (Personal Access Token)')
241244
parser.add_argument('-N', '--no-auth', dest='no_auth', action='store_true', default=False, help='Use no authentication')
242245
parser.add_argument('-j', '--jira', dest='jira_url', default='http://jira.example.com', help='JIRA Base URL (with protocol)')
243246
parser.add_argument('-f', '--file', dest='image_file', default='issue_graph.png', help='Filename to write image to')
@@ -271,9 +274,12 @@ def append_unique(acc, item):
271274
def main():
272275
options = parse_args()
273276

274-
if options.cookie is not None:
277+
if options.bearer is not None:
278+
# Generate JIRA Personal Access Token and use --bearer=ABCDEF012345 commandline argument
279+
auth = {'Authorization': 'Bearer ' + options.bearer}
280+
elif options.cookie is not None:
275281
# Log in with browser and use --cookie=ABCDEF012345 commandline argument
276-
auth = options.cookie
282+
auth = {'JSESSIONID': options.cookie}
277283
elif options.no_auth is True:
278284
# Don't use authentication when it's not needed
279285
auth = None

0 commit comments

Comments
 (0)