Created
November 10, 2016 19:24
-
-
Save jamstooks/8c92c52eba394bfc0345c806e4e88234 to your computer and use it in GitHub Desktop.
Potential signature generator method for MemberSuite SOAP API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from base64 import b64encode | |
from hashlib import sha1 | |
import hmac | |
def hash_signature(url, association_id, secret_access_key, session_id=None): | |
""" | |
Process from Membersuite Docs: http://bit.ly/2eSIDxz | |
""" | |
data = "%s%s" % (url, association_id) | |
if session_id: | |
data = "%s%s" % (data, session_id) | |
data_b = bytearray(data, 'utf-8') | |
secret_b = bytearray(secret_access_key, 'utf-8') | |
hashed = hmac.new(secret_b, data_b, sha1) | |
return hashed.digest().encode("base64").rstrip('\n') | |
""" | |
TESTS | |
""" | |
import unittest | |
class SignatureTest(unittest.TestCase): | |
def test(self): | |
secret = u'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==' | |
url = u"http://membersuite.com/contracts/IConciergeAPIService/WhoAmI" | |
association_id = u"00000000-0000-0000-0000-000000000000" | |
session_id = u"11111111-1111-1111-1111-111111111111" | |
self.assertEqual( | |
hash_signature(url, association_id, secret, session_id), | |
"2zsMYdHb/MJUeTjv5cQl5pBuIqU=") | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Test from documentation, not currently passing. Why?
usage:
python signature.py
to test.