plain.js 1002 B

1234567891011121314151617181920212223242526
  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. async auth(authContext) {
  10. const { connection, credentials } = authContext;
  11. if (!credentials) {
  12. throw new error_1.MongoMissingCredentialsError('AuthContext must provide credentials.');
  13. }
  14. const { username, password } = credentials;
  15. const payload = new bson_1.Binary(Buffer.from(`\x00${username}\x00${password}`));
  16. const command = {
  17. saslStart: 1,
  18. mechanism: 'PLAIN',
  19. payload: payload,
  20. autoAuthorize: 1
  21. };
  22. await connection.commandAsync((0, utils_1.ns)('$external.$cmd'), command, undefined);
  23. }
  24. }
  25. exports.Plain = Plain;
  26. //# sourceMappingURL=plain.js.map