{"id":215,"date":"2018-08-19T15:55:20","date_gmt":"2018-08-19T15:55:20","guid":{"rendered":"https:\/\/raju.guide\/?p=215"},"modified":"2018-09-26T18:23:59","modified_gmt":"2018-09-26T18:23:59","slug":"oauth-with-jira","status":"publish","type":"post","link":"https:\/\/raju.guide\/index.php\/2018\/08\/19\/oauth-with-jira\/","title":{"rendered":"OAuth with Jira"},"content":{"rendered":"\n<p class=\"has-drop-cap\">Jira provides rich set of REST APIs for user interaction through automation. One can authenticate with these REST APIs in three different ways:<strong> 1)<\/strong> Using Basic Auth <strong>2)<\/strong> Cookie based Auth and <strong>3)<\/strong> Using OAuth Token<br\/><br\/>It&#8217;s recommended one should use last two options specially with <strong>OAuth Token<\/strong>. <em>In this tutorial we will learn how to generate OAuth token that you can use within your code.<\/em><br\/><\/p>\n\n\n\n<p><strong>Pr-requisite<\/strong>: <br\/>* Availability of <em>OpenSSL command line<\/em><br\/>* <em>Python 3<\/em><em><br\/>* Get Jira\u00a0<a href=\"https:\/\/github.com\/rkadam\/jira-oauth-generator\">OAuth Generator library<\/a> from Github<\/em><\/p>\n\n\n\n<p><em><\/em><\/p>\n\n\n\n<p><em><\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Steps<br\/><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Clone <a href=\"https:\/\/github.com\/rkadam\/jira-oauth-generator\">Jira OAuth Generator<\/a> library from GitHub<\/li><li>Python 3 Setup<ul><li>Create Python Virtual Environment<ul><li>mkvirtualenv -p python3 jira_oauth1_py3_env<\/li><\/ul><\/li><li>Activate this environment to work on<ul><li>workon jira_oauth1_py3_en<\/li><\/ul><\/li><li>Install all required libraries<ul><li>pip install -r requirements.txt<\/li><\/ul><\/li><\/ul><\/li><li>Generate RSA public and private keys<br\/><em>openssl genrsa -out oauth.pem 1024<\/em><br\/><em>openssl rsa -in oauth.pem -pubout -out oauth.pub<\/em><br\/><ul><li><em>You will need to share this public key oauth.pub with Jira Admins as it will be needed during <a href=\"https:\/\/raju.guide\/index.php\/2018\/08\/20\/application-link-creation-for-jira-oauth\/\">Application link &#8211; Incoming Authentication Setup process<\/a>. Proceed to next step after you have Jira Admins create <strong>application link<\/strong> on your behalf<\/em>.<br\/><\/li><li>Make sure both files are in <strong>config<\/strong> directory<\/li><\/ul><\/li><li>Performing OAuth Dance<ul><li>Through Web browser login to Jira as a user for which you want to generate OAuth token.<br\/><\/li><li>From command line, run python script <br\/>python jira_oauth_token_generator.py config\/starter_oauth.config<br\/><\/li><li>Copy and paste link in browser as suggested. You will be asked to *Authorize \/ Decline* Upon authorization, you will get final access token information. <ul><li>This oauth_token and oauth_token_secret data points you will need later to authenticate yourself while using OAuth with Jira.<\/li><\/ul><\/li><\/ul><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">How to use OAuth to access Jira<\/h2>\n\n\n\n<p style=\"text-align:left\">Couple of ways you can Access using Python.<br\/><br\/>1. Using <a href=\"https:\/\/jira.readthedocs.io\/en\/master\/\"><strong>Python Jira<\/strong><\/a>\u00a0library (<em>recommended<\/em>): <br\/>Take a look at <a href=\"https:\/\/github.com\/rkadam\/jira-oauth-generator\/blob\/master\/access_using_jira_library.py\">access_using_jira_library.py<\/a> to find out how you can use OAuth with this library.<br\/><strong>(jira_oauth1_py3_env) \u279c jira-oauth-generator git:(master) \u2717 python access_using_jira_library.py config\/final_oauth_token.config<\/strong><br\/><br\/><em>Retrieving Issue: EXJIRA-123<\/em><br\/><em>Issue: EXJIRA-123,\u00a0 Summary: Deploy new JIRA Version<\/em><br\/><br\/><em>Retrieving 1st 3 Jira Projects available to you<\/em><br\/><em>First 3 Projects are [&#8216;ABC&#8217;, &#8216;EDF&#8217;, &#8216;EXJIRA&#8217;]<\/em><br\/><\/p>\n\n\n\n<p>2. Using bare bones Jira REST API along with <a href=\"http:\/\/docs.python-requests.org\/en\/master\/\">Requests<\/a> Library:<br\/>Take a look at <a href=\"https:\/\/github.com\/rkadam\/jira-oauth-generator\/blob\/master\/access_using_requests_package.py\">access_using_requests_package.py<\/a> to find out how you can use OAuth to access Jira with out box REST APIs.<br\/><strong>(jira_oauth1_py3_env) \u279c jira-oauth-generator git:(master) \u2717 python access_using_requests_package.py config\/final_oauth_token.config<br\/><br\/><\/strong><em>Retrieving 1st Jira Project available to you<strong><br\/>(ABC) American Born Car<br\/><\/strong><\/em><br\/><em>Adding comment to issue ABC-123<\/em><br\/><strong>Comment successfully added<\/strong>. Please verify through browser!<br\/><br\/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s recommended one should use last two options specially with OAuth Token. In this tutorial we will learn how &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4,5],"tags":[3],"class_list":{"0":"post-215","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-atlassian","7":"category-jira","8":"tag-jira","10":"without-featured-image"},"jetpack_sharing_enabled":true,"featured_image_src":null,"featured_image_src_square":null,"author_info":{"display_name":"adminraju","author_link":"https:\/\/raju.guide\/index.php\/author\/adminraju\/"},"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/posts\/215"}],"collection":[{"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/comments?post=215"}],"version-history":[{"count":14,"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/posts\/215\/revisions"}],"predecessor-version":[{"id":299,"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/posts\/215\/revisions\/299"}],"wp:attachment":[{"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/media?parent=215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/categories?post=215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/raju.guide\/index.php\/wp-json\/wp\/v2\/tags?post=215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}