import { getHTTPClient } from "../../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 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 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 getHTTPClient().post(
    "/oauth2/v1/token/introspection",
    params
  );
  return data;
};
export {
  getToken,
  introspectToken,
  revokeToken
};
