"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-client-password/client-password-strategy-factory-provider.ts
var client_password_strategy_factory_provider_exports = {};
__export(client_password_strategy_factory_provider_exports, {
  ClientPasswordStrategyFactoryProvider: () => ClientPasswordStrategyFactoryProvider
});
module.exports = __toCommonJS(client_password_strategy_factory_provider_exports);
var import_core2 = require("@loopback/core");
var import_rest = require("@loopback/rest");
var ClientPasswordStrategy = __toESM(require("passport-oauth2-client-password"), 1);

// 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-client-password/client-password-strategy-factory-provider.ts
var ClientPasswordStrategyFactoryProvider = class {
  constructor(verifier) {
    this.verifier = verifier;
  }
  value() {
    return (options, verifier) => this.getClientPasswordVerifier(options, verifier);
  }
  getClientPasswordVerifier(options, verifierPassed) {
    const verifyFn = verifierPassed ?? this.verifier;
    if (options == null ? void 0 : options.passReqToCallback) {
      return new ClientPasswordStrategy.Strategy(
        options,
        // eslint-disable-next-line @typescript-eslint/no-misused-promises
        async (req, clientId, clientSecret, cb) => {
          try {
            const client = await verifyFn(clientId, clientSecret, req);
            if (!client) {
              throw new import_rest.HttpErrors.Unauthorized("Client Invalid" /* ClientInvalid */);
            } else if (!client.clientSecret || client.clientSecret !== clientSecret) {
              throw new import_rest.HttpErrors.Unauthorized(
                "Client Verification Failed" /* ClientVerificationFailed */
              );
            }
            cb(null, client);
          } catch (err) {
            cb(err);
          }
        }
      );
    } else {
      return new ClientPasswordStrategy.Strategy(
        // eslint-disable-next-line @typescript-eslint/no-misused-promises
        async (clientId, clientSecret, cb) => {
          try {
            const client = await verifyFn(clientId, clientSecret);
            if (!client) {
              throw new import_rest.HttpErrors.Unauthorized("Client Invalid" /* ClientInvalid */);
            } else if (!client.clientSecret || client.clientSecret !== clientSecret) {
              throw new import_rest.HttpErrors.Unauthorized(
                "Client Verification Failed" /* ClientVerificationFailed */
              );
            }
            cb(null, client);
          } catch (err) {
            cb(err);
          }
        }
      );
    }
  }
};
ClientPasswordStrategyFactoryProvider = __decorateClass([
  __decorateParam(0, (0, import_core2.inject)(Strategies.Passport.OAUTH2_CLIENT_PASSWORD_VERIFIER))
], ClientPasswordStrategyFactoryProvider);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ClientPasswordStrategyFactoryProvider
});
//# sourceMappingURL=client-password-strategy-factory-provider.cjs.map