x509.js 646 B

1234567891011121314151617181920212223242526
  1. 'use strict';
  2. const AuthProvider = require('./auth_provider').AuthProvider;
  3. /**
  4. * Creates a new X509 authentication mechanism
  5. * @class
  6. * @extends AuthProvider
  7. */
  8. class X509 extends AuthProvider {
  9. /**
  10. * Implementation of authentication for a single connection
  11. * @override
  12. */
  13. _authenticateSingleConnection(sendAuthCommand, connection, credentials, callback) {
  14. const username = credentials.username;
  15. const command = { authenticate: 1, mechanism: 'MONGODB-X509' };
  16. if (username) {
  17. command.user = username;
  18. }
  19. sendAuthCommand(connection, '$external.$cmd', command, callback);
  20. }
  21. }
  22. module.exports = X509;