Application link creation for Jira OAuth

In order to access Jira using OAuth token, we also need to create Jira Application link using public key that you have generated as a first step.

Steps for Application Link creation in JIRA

  1. Click on Add Application Link
    1. Give any application URL that you like (and which doesn’t exists) such as https://jira-oauth-rest-api-access or http://example.com etc.
    2. You will see error No response was received from the URL you entered… Ignore it and click on Continue
    3. Application Name: JIRA OAuth REST API Access
    4. Application Type: Generic Application
    5. Click on Create
    6. Click on Edit for newly created Application link with name JIRA OAuth REST API Access.
    7. Click on Configure -> Incoming Authentication
      1. Consumer Key: jira-oauth-rest-api-access
      2. Consumer Name: jira-oauth-rest-api-access
      3. Description: <Some description if you like>
      4. Public Key: <copy it from jira_oauth.pub>
      5. Rest of the fields leave empty
    8. Now Incoming Authentication status should be shown as Configured.

 

OAuth with Jira

Jira provides rich set of REST APIs for user interaction through automation. One can authenticate with these REST APIs in three different ways: 1) Using Basic Auth 2) Cookie based Auth and 3) Using OAuth Token

It’s recommended one should use last two options specially with OAuth Token. In this tutorial we will learn how to generate OAuth token that you can use within your code.

Pr-requisite:
* Availability of OpenSSL command line
* Python 3
* Get Jira OAuth Generator library from Github

Steps

  • Clone Jira OAuth Generator library from GitHub
  • Python 3 Setup
    • Create Python Virtual Environment
      • mkvirtualenv -p python3 jira_oauth1_py3_env
    • Activate this environment to work on
      • workon jira_oauth1_py3_en
    • Install all required libraries
      • pip install -r requirements.txt
  • Generate RSA public and private keys
    openssl genrsa -out oauth.pem 1024
    openssl rsa -in oauth.pem -pubout -out oauth.pub
  • Performing OAuth Dance
    • Through Web browser login to Jira as a user for which you want to generate OAuth token.
    • From command line, run python script
      python jira_oauth_token_generator.py config/starter_oauth.config
    • Copy and paste link in browser as suggested. You will be asked to *Authorize / Decline* Upon authorization, you will get final access token information.
      • This oauth_token and oauth_token_secret data points you will need later to authenticate yourself while using OAuth with Jira.

How to use OAuth to access Jira

Couple of ways you can Access using Python.

1. Using Python Jira library (recommended):
Take a look at access_using_jira_library.py to find out how you can use OAuth with this library.
(jira_oauth1_py3_env) ➜ jira-oauth-generator git:(master) ✗ python access_using_jira_library.py config/final_oauth_token.config

Retrieving Issue: EXJIRA-123
Issue: EXJIRA-123,  Summary: Deploy new JIRA Version

Retrieving 1st 3 Jira Projects available to you
First 3 Projects are [‘ABC’, ‘EDF’, ‘EXJIRA’]

2. Using bare bones Jira REST API along with Requests Library:
Take a look at access_using_requests_package.py to find out how you can use OAuth to access Jira with out box REST APIs.
(jira_oauth1_py3_env) ➜ jira-oauth-generator git:(master) ✗ python access_using_requests_package.py config/final_oauth_token.config

Retrieving 1st Jira Project available to you
(ABC) American Born Car

Adding comment to issue ABC-123
Comment successfully added. Please verify through browser!