"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);

// src/strategies/passport/passport-resource-owner-password/oauth2-resource-owner-password-grant.ts
var oauth2_resource_owner_password_grant_exports = {};
__export(oauth2_resource_owner_password_grant_exports, {
  Oauth2ResourceOwnerPassword: () => Oauth2ResourceOwnerPassword
});
module.exports = __toCommonJS(oauth2_resource_owner_password_grant_exports);
var passport = __toESM(require("passport"), 1);
var Oauth2ResourceOwnerPassword;
((Oauth2ResourceOwnerPassword2) => {
  class Strategy2 extends passport.Strategy {
    constructor(options, verify) {
      super();
      if (verify) {
        this.passReqToCallback = options.passReqToCallback;
        this.verify = verify;
      } else {
        this.passReqToCallback = false;
        this.verify = options;
      }
      this.name = "oauth2-resource-owner-password";
    }
    authenticate(req, options) {
      var _a, _b, _c;
      if (
        /* eslint-disable @typescript-eslint/prefer-optional-chain */
        !req.body || !((_a = req.body) == null ? void 0 : _a["client_id"]) || !((_b = req.body) == null ? void 0 : _b["username"]) || !((_c = req.body) == null ? void 0 : _c["password"])
      ) {
        this.fail();
        return;
      }
      const clientId = req.body["client_id"];
      const clientSecret = req.body["client_secret"];
      const username = req.body["username"];
      const password = req.body["password"];
      const verified = (err, client, user) => {
        if (err) {
          this.error(err);
          return;
        }
        if (!client) {
          this.fail();
          return;
        }
        if (!user) {
          this.fail();
          return;
        }
        this.success(user);
      };
      if (this.passReqToCallback) {
        this.verify(
          req,
          clientId,
          clientSecret,
          username,
          password,
          verified
        );
      } else {
        this.verify(
          clientId,
          clientSecret,
          username,
          password,
          verified
        );
      }
    }
  }
  Oauth2ResourceOwnerPassword2.Strategy = Strategy2;
})(Oauth2ResourceOwnerPassword || (Oauth2ResourceOwnerPassword = {}));
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  Oauth2ResourceOwnerPassword
});
//# sourceMappingURL=oauth2-resource-owner-password-grant.cjs.map