"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 auth_exports = {};
__export(auth_exports, {
  getToken: () => getToken,
  introspectToken: () => introspectToken,
  revokeToken: () => revokeToken
});
module.exports = __toCommonJS(auth_exports);
var import_http_client = require("../../communication/http-client/index.js");
const getToken = async ({
  code,
  clientId,
  scope,
  redirectUri
}) => {
  const params = new URLSearchParams();
  params.append("grant_type", "authorization_code");
  params.append("client_id", clientId);
  params.append("redirect_uri", redirectUri);
  params.append("scope", scope);
  params.append("code", code);
  const { data } = await (0, import_http_client.getHTTPClient)().post(
    "/oauth2/v1/token",
    params
  );
  return { tokenType: data.token_type, accessToken: data.access_token };
};
const revokeToken = async ({ clientId, token }) => {
  const params = new URLSearchParams();
  params.append("token", token);
  params.append("client_id", clientId);
  await (0, import_http_client.getHTTPClient)().post("/oauth2/v1/token/revocation", params);
};
const introspectToken = async ({
  clientId,
  accessToken
}) => {
  const params = new URLSearchParams();
  params.append("token", accessToken);
  params.append("client_id", clientId);
  const { data } = await (0, import_http_client.getHTTPClient)().post(
    "/oauth2/v1/token/introspection",
    params
  );
  return data;
};
