credentials.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. //
  3. //
  4. // Different kind of credentials that can be supplied when opening a
  5. // connection, corresponding to SASL mechanisms There's only two
  6. // useful mechanisms that RabbitMQ implements:
  7. // * PLAIN (send username and password in the plain)
  8. // * EXTERNAL (assume the server will figure out who you are from
  9. // context, i.e., your SSL certificate)
  10. var codec = require('./codec')
  11. module.exports.plain = function(user, passwd) {
  12. return {
  13. mechanism: 'PLAIN',
  14. response: function() {
  15. return Buffer.from(['', user, passwd].join(String.fromCharCode(0)))
  16. },
  17. username: user,
  18. password: passwd
  19. }
  20. }
  21. module.exports.amqplain = function(user, passwd) {
  22. return {
  23. mechanism: 'AMQPLAIN',
  24. response: function() {
  25. const buffer = Buffer.alloc(16384);
  26. const size = codec.encodeTable(buffer, { LOGIN: user, PASSWORD: passwd}, 0);
  27. return buffer.subarray(4, size);
  28. },
  29. username: user,
  30. password: passwd
  31. }
  32. }
  33. module.exports.external = function() {
  34. return {
  35. mechanism: 'EXTERNAL',
  36. response: function() { return Buffer.from(''); }
  37. }
  38. }