var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
  get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
  if (typeof require !== "undefined")
    return require.apply(this, arguments);
  throw new Error('Dynamic require of "' + x + '" is not supported');
});

// src/strategy-adapter.ts
import { HttpErrors } from "@loopback/rest";
var passportRequestMixin = __require("passport/lib/http/request");
var StrategyAdapter = class {
  /**
   * @param strategy instance of a class which implements a passport-strategy;
   * @description http://passportjs.org/
   */
  constructor(strategy) {
    this.strategy = strategy;
  }
  /**
   * The function to invoke the contained passport strategy.
   *     1. Create an instance of the strategy
   *     2. add success and failure state handlers
   *     3. authenticate using the strategy
   * @param request The incoming request.
   */
  authenticate(request, response, options) {
    return new Promise((resolve, reject) => {
      for (const key in passportRequestMixin) {
        request[key] = passportRequestMixin[key];
      }
      const strategy = Object.create(this.strategy);
      strategy.success = (t) => {
        resolve(t);
      };
      strategy.fail = (challenge) => {
        reject(new HttpErrors.Unauthorized(challenge));
      };
      strategy.error = (error) => {
        reject(new HttpErrors.Unauthorized(error));
      };
      strategy.redirect = (url) => {
        if (response) {
          response.redirect(302, url);
        }
        resolve();
      };
      strategy.authenticate(request, options ?? {});
    });
  }
};
export {
  StrategyAdapter
};
//# sourceMappingURL=strategy-adapter.js.map