Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime
- from base64 import urlsafe_b64encode
- import json
- from Crypto.Cipher import AES
- from Crypto.Random import get_random_bytes
- from Crypto.Hash import SHA256, HMAC
- class ShopifyMultipass:
- def __init__(self, secret):
- pass
- def generateShopifyUrl(self, secret, customerDataHash, url):
- key = SHA256.new(secret.encode('utf-8')).digest()
- self.encryptionKey = key[0:16]
- self.signatureKey = key[16:32]
- currentDate = datetime.datetime.utcnow().isoformat()
- customerDataHash['created_at'] = currentDate
- plainText = json.dumps(customerDataHash)
- plainText2 = plainText + (AES.block_size - len(plainText) % AES.block_size) * chr(
- AES.block_size - len(plainText) % AES.block_size)
- iv = get_random_bytes(AES.block_size)
- cipher = AES.new(self.encryptionKey, AES.MODE_CBC, iv)
- cipherText = iv + cipher.encrypt(plainText2.encode('utf-8'))
- signedText = HMAC.new(self.signatureKey, secret.encode('utf-8'), SHA256).digest()
- token = urlsafe_b64encode(cipherText + signedText).decode('utf-8')
- return '{0}/account/login/multipass/{1}'.format(url, token)
- from shopifymultipass import ShopifyMultipass
- multipass = ShopifyMultipass()
- customerData = {
- 'email': 'amol@mydomain.com',
- 'return_to': 'https://ourshop.myshopify.com/collections/all',
- 'first_name': 'Amol',
- 'last_name': 'Chakane' }
- url = multipass.generateShopifyUrl('Shopify_Multipass_Secret', customerData, 'http://ourshop.myshopify.com');
Add Comment
Please, Sign In to add comment