Guest User

Untitled

a guest
Jan 23rd, 2018
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. var qs = require('querystring'),
  2. crypto = require('crypto');
  3.  
  4. exports.sign = function (opt) {
  5. var data = new Buffer(JSON.stringify(opt.details), 'utf8'),
  6. iv = new Buffer('OpenSSL for Ruby', 'utf8'),
  7. i = 0,
  8. sha1 = crypto.createHash('sha1'),
  9. hash, cipher, ret;
  10.  
  11. //add to the hash
  12. sha1.update(opt.apiKey + opt.siteKey);
  13. //slice it as only 16 bytes will be used for the key
  14. hash = new Buffer(sha1.digest(), 'binary').slice(0,16);
  15. //now do the iv xor thing
  16. for (i = 0; i < 16; i++)
  17. data[i] = data[i] ^ iv[i];
  18.  
  19. //create a cipher
  20. cipher = crypto.createCipheriv('aes-128-cbc', hash.toString('binary'), iv.toString('binary'));
  21. //update the data
  22. ret = cipher.update(data.toString('utf8'), 'utf8', 'base64');
  23. ret += cipher.final('base64');
  24.  
  25.  
  26. return ret
  27. .replace(/=*$/, '')
  28. .replace(/\n/, '')
  29. .replace(/\+/, '-')
  30. .replace(/\//, '_');
  31. };
  32. /**
  33. * returns the multipass sso auth url for assitly
  34. * e.g.:
  35. * multipass({
  36. * host: "help.yourcompany.com",
  37. * details: {
  38. * uid: "123",
  39. * expires: '2011-08-30T00:00:00Z',
  40. * customer_email: 'youruser@yourcompany.com',
  41. * customer_name: 'Your User'
  42. * },
  43. * apiKey: '4e3b17bad70233ca20000004',
  44. * siteKey: 'yourcompany'
  45. * });
  46. *
  47. *
  48. */
  49.  
  50.  
  51. exports.multipass = function (opt) {
  52. var url =
  53. (opt.secure ? "https" : "http") +
  54. '://' +
  55. opt.host +
  56. '/customer/authentication/multipass/callback?multipass=' +
  57. qs.escape(exports.sign(opt));
  58.  
  59. return url;
  60. };
Add Comment
Please, Sign In to add comment