var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
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-verify.provider.ts
import { HttpErrors } from "@loopback/rest";
var ClientPasswordVerifyProvider = class {
  constructor() {
  }
  value() {
    return async (clientId, clientSecret) => {
      throw new HttpErrors.NotImplemented(
        `VerifyFunction.OauthClientPasswordFn is not implemented`
      );
    };
  }
};

// src/strategies/passport/passport-client-password/client-password-strategy-factory-provider.ts
import { inject } from "@loopback/core";
import { HttpErrors as HttpErrors2 } from "@loopback/rest";
import * as ClientPasswordStrategy from "passport-oauth2-client-password";

// src/strategies/keys.ts
import { BindingKey } from "@loopback/core";
var Strategies;
((Strategies2) => {
  let Passport;
  ((Passport2) => {
    Passport2.LOCAL_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.localPassword"
    );
    Passport2.LOCAL_PASSWORD_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.localPassword"
    );
    Passport2.OTP_AUTH_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.otpAuth"
    );
    Passport2.OTP_VERIFIER = BindingKey.create("bleco.passport.verifier.otpAuth");
    Passport2.CLIENT_PASSWORD_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.clientPassword"
    );
    Passport2.OAUTH2_CLIENT_PASSWORD_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.oauth2ClientPassword"
    );
    Passport2.BEARER_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.bearer"
    );
    Passport2.BEARER_TOKEN_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.bearerToken"
    );
    Passport2.RESOURCE_OWNER_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.resourceOwnerPassword"
    );
    Passport2.RESOURCE_OWNER_PASSWORD_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.resourceOwnerPassword"
    );
    Passport2.GOOGLE_OAUTH2_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.googleOauth2"
    );
    Passport2.GOOGLE_OAUTH2_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.googleOauth2"
    );
    Passport2.AZURE_AD_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.azureAd"
    );
    Passport2.AZURE_AD_VERIFIER = BindingKey.create("bleco.passport.verifier.azureAd");
    Passport2.KEYCLOAK_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.keycloak"
    );
    Passport2.KEYCLOAK_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.keycloak"
    );
    Passport2.INSTAGRAM_OAUTH2_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.instagramOauth2"
    );
    Passport2.INSTAGRAM_OAUTH2_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.instagramOauth2"
    );
    Passport2.FACEBOOK_OAUTH2_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.facebookOauth2"
    );
    Passport2.FACEBOOK_OAUTH2_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.facebookOauth2"
    );
    Passport2.APPLE_OAUTH2_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.appleOauth2"
    );
    Passport2.APPLE_OAUTH2_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.appleOauth2"
    );
    Passport2.COGNITO_OAUTH2_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.cognitoOauth2"
    );
    Passport2.COGNITO_OAUTH2_VERIFIER = BindingKey.create(
      "bleco.passport.verifier.cognitoOauth2"
    );
    Passport2.SAML_STRATEGY_FACTORY = BindingKey.create(
      "bleco.passport.strategyFactory.saml"
    );
    Passport2.SAML_VERIFIER = 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 HttpErrors2.Unauthorized("Client Invalid" /* ClientInvalid */);
            } else if (!client.clientSecret || client.clientSecret !== clientSecret) {
              throw new HttpErrors2.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 HttpErrors2.Unauthorized("Client Invalid" /* ClientInvalid */);
            } else if (!client.clientSecret || client.clientSecret !== clientSecret) {
              throw new HttpErrors2.Unauthorized(
                "Client Verification Failed" /* ClientVerificationFailed */
              );
            }
            cb(null, client);
          } catch (err) {
            cb(err);
          }
        }
      );
    }
  }
};
ClientPasswordStrategyFactoryProvider = __decorateClass([
  __decorateParam(0, inject(Strategies.Passport.OAUTH2_CLIENT_PASSWORD_VERIFIER))
], ClientPasswordStrategyFactoryProvider);
export {
  ClientPasswordStrategyFactoryProvider,
  ClientPasswordVerifyProvider
};
//# sourceMappingURL=index.js.map