"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __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-insta-oauth2/insta-auth-strategy-factory-provider.ts
var insta_auth_strategy_factory_provider_exports = {};
__export(insta_auth_strategy_factory_provider_exports, {
  InstagramAuthStrategyFactoryProvider: () => InstagramAuthStrategyFactoryProvider
});
module.exports = __toCommonJS(insta_auth_strategy_factory_provider_exports);
var import_core2 = require("@loopback/core");
var import_rest = require("@loopback/rest");
var import_https_proxy_agent = require("https-proxy-agent");
var import_passport_instagram = require("passport-instagram");

// 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-insta-oauth2/insta-auth-strategy-factory-provider.ts
var InstagramAuthStrategyFactoryProvider = class {
  constructor(verifierInstagramAuth) {
    this.verifierInstagramAuth = verifierInstagramAuth;
  }
  value() {
    return (options, verifier) => this.getInstagramAuthStrategyVerifier(options, verifier);
  }
  getInstagramAuthStrategyVerifier(options, verifierPassed) {
    const verifyFn = verifierPassed ?? this.verifierInstagramAuth;
    let strategy;
    if (options && options.passReqToCallback === true) {
      strategy = new import_passport_instagram.Strategy(
        options,
        // eslint-disable-next-line @typescript-eslint/no-misused-promises
        async (req, accessToken, refreshToken, profile, cb) => {
          try {
            const user = await verifyFn(
              accessToken,
              refreshToken,
              profile,
              cb,
              req
            );
            if (!user) {
              throw new import_rest.HttpErrors.Unauthorized(
                "Invalid Credentials" /* InvalidCredentials */
              );
            }
            cb(void 0, user);
          } catch (err) {
            cb(err);
          }
        }
      );
    } else {
      strategy = new import_passport_instagram.Strategy(
        options,
        // eslint-disable-next-line @typescript-eslint/no-misused-promises
        async (accessToken, refreshToken, profile, cb) => {
          try {
            const user = await verifyFn(accessToken, refreshToken, profile, cb);
            if (!user) {
              throw new import_rest.HttpErrors.Unauthorized(
                "Invalid Credentials" /* InvalidCredentials */
              );
            }
            cb(void 0, user);
          } catch (err) {
            cb(err);
          }
        }
      );
    }
    this._setupProxy(strategy);
    return strategy;
  }
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  _setupProxy(strategy) {
    let httpsProxyAgent;
    if (process.env["https_proxy"]) {
      httpsProxyAgent = new import_https_proxy_agent.HttpsProxyAgent(process.env["https_proxy"]);
      strategy._oauth2.setAgent(httpsProxyAgent);
    } else if (process.env["HTTPS_PROXY"]) {
      httpsProxyAgent = new import_https_proxy_agent.HttpsProxyAgent(process.env["HTTPS_PROXY"]);
      strategy._oauth2.setAgent(httpsProxyAgent);
    }
  }
};
InstagramAuthStrategyFactoryProvider = __decorateClass([
  __decorateParam(0, (0, import_core2.inject)(Strategies.Passport.INSTAGRAM_OAUTH2_VERIFIER))
], InstagramAuthStrategyFactoryProvider);
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  InstagramAuthStrategyFactoryProvider
});
//# sourceMappingURL=insta-auth-strategy-factory-provider.cjs.map