1 ##############################################################################
2 # Copyright (c) 2016 Max Breitenfeldt and others.
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ##############################################################################
14 import oauth2 as oauth
15 from django.conf import settings
17 from tlslite.utils import keyfactory
20 class SignatureMethod_RSA_SHA1(oauth.SignatureMethod):
23 def signing_base(self, request, consumer, token):
24 if not hasattr(request, 'normalized_url') or request.normalized_url is None:
25 raise ValueError("Base URL for request is not set.")
28 oauth.escape(request.method),
29 oauth.escape(request.normalized_url),
30 oauth.escape(request.get_normalized_parameters()),
33 key = '%s&' % oauth.escape(consumer.secret)
35 key += oauth.escape(token.secret)
39 def sign(self, request, consumer, token):
40 """Builds the base signature string."""
41 key, raw = self.signing_base(request, consumer, token)
43 module_dir = os.path.dirname(__file__) # get current directory
44 with open(module_dir + '/rsa.pem', 'r') as f:
46 privateKeyString = data.strip()
47 privatekey = keyfactory.parsePrivateKey(privateKeyString)
49 signature = privatekey.hashAndSign(raw)
50 return base64.b64encode(signature)
54 module_dir = os.path.dirname(__file__) # get current directory
55 with open(module_dir + '/rsa.pem', 'r') as f:
59 'access_token': user.userprofile.oauth_token,
60 'access_token_secret': user.userprofile.oauth_secret,
61 'consumer_key': settings.OAUTH_CONSUMER_KEY,
65 return JIRA(server=settings.JIRA_URL, oauth=oauth_dict)