#!/usr/bin/env python |
# Lifted from http://bit.ly/1qpxJlj |
fromoauthlib.oauth1importSIGNATURE_RSA |
fromrequests_oauthlibimportOAuth1Session |
defread(file_path): |
'' Read a file and return it's contents. '' |
withopen(file_path) asf: |
returnf.read() |
# The Consumer Key created while setting up the 'Incoming Authentication' in |
# JIRA for the Application Link. |
CONSUMER_KEY=u' |
# The contents of the rsa.pem file generated (the private RSA key) |
RSA_KEY=read('/path/to/jira.pem') |
# The URLs for the JIRA instance |
JIRA_SERVER='https://stackstorm.atlassian.net' |
REQUEST_TOKEN_URL=JIRA_SERVER+'/plugins/servlet/oauth/request-token' |
AUTHORIZE_URL=JIRA_SERVER+'/plugins/servlet/oauth/authorize' |
ACCESS_TOKEN_URL=JIRA_SERVER+'/plugins/servlet/oauth/access-token' |
# Step 1: Get a request token |
oauth=OAuth1Session(CONSUMER_KEY, signature_type='auth_header', |
signature_method=SIGNATURE_RSA, rsa_key=RSA_KEY) |
request_token=oauth.fetch_request_token(REQUEST_TOKEN_URL) |
print('STEP 1: GET REQUEST TOKEN') |
print(' oauth_token={}'.format(request_token['oauth_token'])) |
print(' oauth_token_secret={}'.format(request_token['oauth_token_secret'])) |
print('n') |
# Step 2: Get the end-user's authorization |
print('STEP2: AUTHORIZATION') |
print(' Visit to the following URL to provide authorization:') |
print(' {}?oauth_token={}'.format(AUTHORIZE_URL, request_token['oauth_token'])) |
print('n') |
whileraw_input('Press any key to continue...'): |
pass |
# XXX: This is an ugly hack to get around the verfication string |
# that the server needs to supply as part of authorization response. |
# But we hard code it. |
oauth._client.client.verifier=u'verified' |
# Step 3: Get the access token |
access_token=oauth.fetch_access_token(ACCESS_TOKEN_URL) |
print('STEP2: GET ACCESS TOKEN') |
print(' oauth_token={}'.format(access_token['oauth_token'])) |
print(' oauth_token_secret={}'.format(access_token['oauth_token_secret'])) |
print('n') |
# Now you can use the access tokens with the JIRA client. Hooray! |
Filename, size | File type | Python version | Upload date | Hashes |
---|---|---|---|---|
Filename, size jira_oauth_generator-0.1.7-py3-none-any.whl (18.6 kB) | File type Wheel | Python version py3 | Upload date | Hashes |
Filename, size jira-oauth-generator-0.1.7.tar.gz (7.8 kB) | File type Source | Python version None | Upload date | Hashes |
Algorithm | Hash digest |
---|---|
SHA256 | 19b1023fe322610f3ebfb3d038c3471a8aa771e5cd622906765601ab3467a9f0 |
MD5 | 34a03e6173fb2ab90340db1f5677adb6 |
BLAKE2-256 | e9c38dbef344fc6ef4ababb4e789cd5a18921c1ec8a34e1f21d6aad54f2a4d6d |
Algorithm | Hash digest |
---|---|
SHA256 | ce6ef7baaa7eb9b877c3935b607e60750d0e2517e2a211654220919fc05bb2be |
MD5 | 0882b87faba791bae86304b73aab9cac |
BLAKE2-256 | 2eb8d087d7e1e77454cda3841e283909f1b7aa5ba63ce33d072fe0f7a4ccae8d |