auth_provider.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.AuthProvider = exports.AuthContext = void 0;
  4. const error_1 = require("../../error");
  5. /**
  6. * Context used during authentication
  7. * @internal
  8. */
  9. class AuthContext {
  10. constructor(connection, credentials, options) {
  11. /** If the context is for reauthentication. */
  12. this.reauthenticating = false;
  13. this.connection = connection;
  14. this.credentials = credentials;
  15. this.options = options;
  16. }
  17. }
  18. exports.AuthContext = AuthContext;
  19. class AuthProvider {
  20. /**
  21. * Prepare the handshake document before the initial handshake.
  22. *
  23. * @param handshakeDoc - The document used for the initial handshake on a connection
  24. * @param authContext - Context for authentication flow
  25. */
  26. async prepare(handshakeDoc, _authContext) {
  27. return handshakeDoc;
  28. }
  29. /**
  30. * Reauthenticate.
  31. * @param context - The shared auth context.
  32. */
  33. async reauth(context) {
  34. if (context.reauthenticating) {
  35. throw new error_1.MongoRuntimeError('Reauthentication already in progress.');
  36. }
  37. try {
  38. context.reauthenticating = true;
  39. await this.auth(context);
  40. }
  41. finally {
  42. context.reauthenticating = false;
  43. }
  44. }
  45. }
  46. exports.AuthProvider = AuthProvider;
  47. //# sourceMappingURL=auth_provider.js.map