Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jira python oauth: how to get the parameters for authentication?

Tags:

python

oauth

jira

I am trying to use oauth to access jira, and I am reading this document: Welcome to jira-python's documentation.

But in this oauth part, I cannot figure out how I can get these parameters:

access_token, access_token_secret, consumer_key, key_cert

like image 595
Cacheing Avatar asked Aug 09 '13 18:08

Cacheing


3 Answers

Unfortunately, other answers don't work with Python 3. I found that https://github.com/rkadam/jira-oauth-generator fully covers Jira OAuth in Python 3.

like image 51
rominf Avatar answered Sep 30 '22 01:09

rominf


I too am using jira-python. Since jira-python uses requests and requests-oauthlib I used those same libraries to implement the OAuth 1 dance necessary to get the tokens.

First, setup JIRA:

  1. Generate RSA public/private key pair (you end up with rsa.pub and rsa.pem files). Your Python code will need access to the private key rsa.pem.
  2. Configure a JIRA application (done in JIRA admin under "Application Links") with "Incoming Authentication" and use the public key generated above. This is where you specify the consumer_key needed by jira-python

Next, the OAuth dance. It's pretty simple with OAuth1Session from requests-oauthlib. Here is a simple example (CLI): JIRA Oauth in Python.

The workflow is described in the requests-oauthlib docs: OAuth 1 Workflow.

So, to summarize:

  • access_token - Obtained at the end of the OAuth 1 Workflow.
  • access_token_secret - Obtained at the end of the OAuth 1 Workflow.
  • consumer_key - Specified when you setup an "Application Link" in JIRA admin.
  • key_cert - The contents of the rsa.pem file (private key). The public key is also added when setting up the "Application Link" in JIRA admin.
like image 13
Micah Carrick Avatar answered Oct 18 '22 08:10

Micah Carrick


First you need to add an application link to JIRA for your application: https://confluence.atlassian.com/display/JIRA060/Configuring+Application+Links

For the case when the application accessing JIRA is not a web application, you can use arbitrary URL as the application URL, but that url will be used to retrieve the application icon when it's displayed in the list of Application Links in administrative UI of JIRA.

Then you would need to do a so called "oauth dance" to get an OAuth token and its corresponding secret. Please take a look at Atlassian examples here: https://bitbucket.org/atlassian_tutorial/atlassian-oauth-examples/src

Those examples are mostly covering the dance itself, while the authentication using OAuth token+secret (which is received during the dance) is documented here: http://jira.readthedocs.io/en/latest/examples.html#oauth. I hope this helps.

At least it worked for me (also in Python for my case). :)

like image 3
Serge Broslavsky Avatar answered Oct 18 '22 09:10

Serge Broslavsky