If you are writing a script that interacts with Jira through a REST API, you should authenticate using an OAuth token, rather than an embedded username/password. Here we describe one way to do the 'oauth dance' to generate a trusted token using Python 3 - specifically the jirashell utility from the jira Python package. jirashell then forms a useful basis for a Python script. Our example script uses OAuth to call an undocumented REST API for querying license data. Last updated
ModuleNotFoundError: No module named 'setuptools_rust'?
If you get an error:
Collecting cryptography>=2.0 (from SecretStorage>=3.2; sys_platform == "linux"->keyring->jira)
Downloading https://files.pythonhosted.org/packages/9b/77/461087a514d2e8ece1c975d8216bc03f7048e6090c5166bc34115afdaa53/cryptography-3.4.7.tar.gz (546kB)
100% |████████████████████████████████| 552kB 2.8MB/s
Complete output from command python setup.py egg_info:
If you are seeing an error here please try the following to
successfully install cryptography:
Upgrade to the latest pip and try again. This will fix errors for most
users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-xs9c9nwd/cryptography/setup.py", line 14, in <module>
from setuptools_rust import RustExtension
ModuleNotFoundError: No module named 'setuptools_rust'
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-xs9c9nwd/cryptography/
If, instead of printing a URL, the jirashell command just prints:
That means your consumer-key does not exist in Jira (perhaps you copy & pasted the example without substituting yours?). This is an error reporting bug in jirashell.
Why BROWSER='echo %s'..
This should print a URL.
At this point you need to decide which JIRA user you want to grant OAuth access as. For most scripts you should create a dedicated JIRA role account with reduced privileges. Log out and back in to JIRA as that user, (or use switchuser.jsp) then open the link:
Click 'Allow' in the Browser window:
After the URL, your terminal also should have displayed:
Your browser is opening the OAuth authorization for this client session.
Have you authorized this program to connect on your behalf to https://issues.redradishtech.com? (y/n)
The jirashell command now proceeds to launch an IPython session:
<JIRA Shell 2.0.0 (https://issues.redradishtech.com)>
*** JIRA shell active; client is in 'jira'. Press Ctrl-D to exit.
Type oauth to print the OAuth object:
Now press ctrl-d to exit.
Test your OAuth token
Now embed the 'consumer_key', 'access_token' and 'access_token_secret' values you saw above into a new jirashell command: