plain.js 1.0 KB

123456789101112131415161718192021222324252627
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.Plain = void 0;
  4. const bson_1 = require("../../bson");
  5. const error_1 = require("../../error");
  6. const utils_1 = require("../../utils");
  7. const auth_provider_1 = require("./auth_provider");
  8. class Plain extends auth_provider_1.AuthProvider {
  9. auth(authContext, callback) {
  10. const { connection, credentials } = authContext;
  11. if (!credentials) {
  12. return callback(new error_1.MongoMissingCredentialsError('AuthContext must provide credentials.'));
  13. }
  14. const username = credentials.username;
  15. const password = credentials.password;
  16. const payload = new bson_1.Binary(Buffer.from(`\x00${username}\x00${password}`));
  17. const command = {
  18. saslStart: 1,
  19. mechanism: 'PLAIN',
  20. payload: payload,
  21. autoAuthorize: 1
  22. };
  23. connection.command((0, utils_1.ns)('$external.$cmd'), command, undefined, callback);
  24. }
  25. }
  26. exports.Plain = Plain;
  27. //# sourceMappingURL=plain.js.map