"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __decorateClass = (decorators, target, key, kind) => {
  var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
  for (var i = decorators.length - 1, decorator; i >= 0; i--)
    if (decorator = decorators[i])
      result = (kind ? decorator(target, key, result) : decorator(result)) || result;
  if (kind && result)
    __defProp(target, key, result);
  return result;
};
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);

// src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts
var otp_strategy_factory_provider_exports = {};
__export(otp_strategy_factory_provider_exports, {
  PassportOtpStrategyFactoryProvider: () => PassportOtpStrategyFactoryProvider
});
module.exports = __toCommonJS(otp_strategy_factory_provider_exports);
var import_core2 = require("@loopback/core");
var import_rest = require("@loopback/rest");

// src/strategies/keys.ts
var import_core = require("@loopback/core");
var Strategies;
((Strategies2) => {
  let Passport;
  ((Passport2) => {
    Passport2.LOCAL_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.localPassword"
    );
    Passport2.LOCAL_PASSWORD_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.localPassword"
    );
    Passport2.OTP_AUTH_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.otpAuth"
    );
    Passport2.OTP_VERIFIER = import_core.BindingKey.create("bleco.passport.verifier.otpAuth");
    Passport2.CLIENT_PASSWORD_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.clientPassword"
    );
    Passport2.OAUTH2_CLIENT_PASSWORD_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.oauth2ClientPassword"
    );
    Passport2.BEARER_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.bearer"
    );
    Passport2.BEARER_TOKEN_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.bearerToken"
    );
    Passport2.RESOURCE_OWNER_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.resourceOwnerPassword"
    );
    Passport2.RESOURCE_OWNER_PASSWORD_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.resourceOwnerPassword"
    );
    Passport2.GOOGLE_OAUTH2_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.googleOauth2"
    );
    Passport2.GOOGLE_OAUTH2_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.googleOauth2"
    );
    Passport2.AZURE_AD_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.azureAd"
    );
    Passport2.AZURE_AD_VERIFIER = import_core.BindingKey.create("bleco.passport.verifier.azureAd");
    Passport2.KEYCLOAK_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.keycloak"
    );
    Passport2.KEYCLOAK_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.keycloak"
    );
    Passport2.INSTAGRAM_OAUTH2_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.instagramOauth2"
    );
    Passport2.INSTAGRAM_OAUTH2_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.instagramOauth2"
    );
    Passport2.FACEBOOK_OAUTH2_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.facebookOauth2"
    );
    Passport2.FACEBOOK_OAUTH2_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.facebookOauth2"
    );
    Passport2.APPLE_OAUTH2_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.appleOauth2"
    );
    Passport2.APPLE_OAUTH2_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.appleOauth2"
    );
    Passport2.COGNITO_OAUTH2_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.cognitoOauth2"
    );
    Passport2.COGNITO_OAUTH2_VERIFIER = import_core.BindingKey.create(
      "bleco.passport.verifier.cognitoOauth2"
    );
    Passport2.SAML_STRATEGY_FACTORY = import_core.BindingKey.create(
      "bleco.passport.strategyFactory.saml"
    );
    Passport2.SAML_VERIFIER = import_core.BindingKey.create("bleco.passport.verifier.saml");
  })(Passport = Strategies2.Passport || (Strategies2.Passport = {}));
})(Strategies || (Strategies = {}));

// src/strategies/passport/passport-otp/otp-auth.ts
var passport = __toESM(require("passport"), 1);
var Otp;
((Otp2) => {
  class Strategy2 extends passport.Strategy {
    constructor(_options, verify) {
      super();
      this.name = "otp";
      if (verify) {
        this.verify = verify;
      }
    }
    authenticate(req, options) {
      const key = req.body.key || (options == null ? void 0 : options.key);
      const otp = req.body.otp || (options == null ? void 0 : options.otp);
      if (!key) {
        this.fail();
        return;
      }
      const verified = (err, user, _info) => {
        if (err) {
          this.error(err);
          return;
        }
        if (!user) {
          this.fail();
          return;
        }
        this.success(user);
      };
      this.verify(key, otp, verified);
    }
  }
  Otp2.Strategy = Strategy2;
})(Otp || (Otp = {}));

// src/strategies/passport/passport-otp/otp-strategy-factory.provider.ts
var PassportOtpStrategyFactoryProvider = class {
  constructor(verifierOtp) {
    this.verifierOtp = verifierOtp;
  }
  value() {
    return (options, verifier) => this.getPassportOtpStrategyVerifier(options, verifier);
  }
  getPassportOtpStrategyVerifier(options, verifierPassed) {
    const verifyFn = verifierPassed ?? this.verifierOtp;
    return new Otp.Strategy(
      options,
      // eslint-disable-next-line @typescript-eslint/no-misused-promises
      async (key, otp, cb) => {
        try {
          const user = await verifyFn(key, otp);
          if (!user) {
            throw new import_rest.HttpErrors.Unauthorized("Invalid Credentials" /* InvalidCredentials */);
          }
          cb(null, user);
        } catch (err) {
          cb(err);
        }
      }
    );
  }
};
PassportOtpStrategyFactoryProvider = __decorateClass([
  __decorateParam(0, (0, import_core2.inject)(Strategies.Passport.OTP_VERIFIER))
], PassportOtpStrategyFactoryProvider);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  PassportOtpStrategyFactoryProvider
});
//# sourceMappingURL=otp-strategy-factory.provider.cjs.map