Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

plain.js 932B

1234567891011121314151617181920212223242526272829303132333435
  1. 'use strict';
  2. const retrieveBSON = require('../connection/utils').retrieveBSON;
  3. const AuthProvider = require('./auth_provider').AuthProvider;
  4. // TODO: can we get the Binary type from this.bson instead?
  5. const BSON = retrieveBSON();
  6. const Binary = BSON.Binary;
  7. /**
  8. * Creates a new Plain authentication mechanism
  9. *
  10. * @extends AuthProvider
  11. */
  12. class Plain extends AuthProvider {
  13. /**
  14. * Implementation of authentication for a single connection
  15. * @override
  16. */
  17. _authenticateSingleConnection(sendAuthCommand, connection, credentials, callback) {
  18. const username = credentials.username;
  19. const password = credentials.password;
  20. const payload = new Binary(`\x00${username}\x00${password}`);
  21. const command = {
  22. saslStart: 1,
  23. mechanism: 'PLAIN',
  24. payload: payload,
  25. autoAuthorize: 1
  26. };
  27. sendAuthCommand(connection, '$external.$cmd', command, callback);
  28. }
  29. }
  30. module.exports = Plain;