Guest User

Untitled

a guest
Jan 23rd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. import datetime
  2. from base64 import urlsafe_b64encode
  3. import json
  4. from Crypto.Cipher import AES
  5. from Crypto.Random import get_random_bytes
  6. from Crypto.Hash import SHA256, HMAC
  7. class ShopifyMultipass:
  8. def __init__(self, secret):
  9. pass
  10.  
  11. def generateShopifyUrl(self, secret, customerDataHash, url):
  12. key = SHA256.new(secret.encode('utf-8')).digest()
  13.  
  14. self.encryptionKey = key[0:16]
  15. self.signatureKey = key[16:32]
  16.  
  17. currentDate = datetime.datetime.utcnow().isoformat()
  18. customerDataHash['created_at'] = currentDate
  19. plainText = json.dumps(customerDataHash)
  20. plainText2 = plainText + (AES.block_size - len(plainText) % AES.block_size) * chr(
  21. AES.block_size - len(plainText) % AES.block_size)
  22. iv = get_random_bytes(AES.block_size)
  23. cipher = AES.new(self.encryptionKey, AES.MODE_CBC, iv)
  24. cipherText = iv + cipher.encrypt(plainText2.encode('utf-8'))
  25. signedText = HMAC.new(self.signatureKey, secret.encode('utf-8'), SHA256).digest()
  26. token = urlsafe_b64encode(cipherText + signedText).decode('utf-8')
  27. return '{0}/account/login/multipass/{1}'.format(url, token)
  28.  
  29. from shopifymultipass import ShopifyMultipass
  30. multipass = ShopifyMultipass()
  31. customerData = {
  32. 'email': 'amol@mydomain.com',
  33. 'return_to': 'https://ourshop.myshopify.com/collections/all',
  34. 'first_name': 'Amol',
  35. 'last_name': 'Chakane' }
  36.  
  37. url = multipass.generateShopifyUrl('Shopify_Multipass_Secret', customerData, 'http://ourshop.myshopify.com');
Add Comment
Please, Sign In to add comment