Make it possible to enable UserVoice in a KARL site.
As a site administrator, I can enable UserVoice integration by providing an API Key and Account key.
from Crypto.Cipher import AES
import base64
import hashlib
import urllib
import operator
import array
import simplejson as json
message = {
"guid" : "1276710098"
"expires" : "2010-06-16 18:11:38",
"display_name" : "Example User",
"email" : "example@test.com",
"url" : "http://example.com/users/1234",
"avatar_url" : "http://example.com/users/1234/avatar.png"
}
block_size = 16
mode = AES.MODE_CBC
api_key = "REPLACE_WITH_REAL_KEY"
account_key = 'REPLACE_WITH_REAL_KEY'
iv = "OpenSSL for Ruby"
json = json.dumps(message, separators=(',',':'))
salted = api_key+account_key
saltedHash = hashlib.sha1(salted).digest()[:16]
json_bytes = array.array('b', json[0 : len(json)])
iv_bytes = array.array('b', iv[0 : len(iv)])
# # xor the iv into the first 16 bytes.
for i in range(0, 16):
json_bytes[i] = operator.xor(json_bytes[i], iv_bytes[i])
pad = block_size - len(json_bytes.tostring()) % block_size
data = json_bytes.tostring() + pad * chr(pad)
aes = AES.new(saltedHash, mode, iv)
encrypted_bytes = aes.encrypt(data)
param_for_uservoice_sso = urllib.quote(base64.b64encode(encrypted_bytes))