Files
openrouter/src/auth/auth.cpp
T
wt cedc9cd995
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Waiting to run
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Waiting to run
making easy
2025-02-20 18:07:59 +07:00

26 lines
724 B
C++

#include <auth/auth.hpp>
#include <httplib.h>
#include <json.hpp>
#include <types.hpp>
#include <config/config.hpp>
bool authenticate(const std::string &token)
{
// config::config.setConfig(std::string("../config.json"));
httplib::Client cli(config::config.getConfig()["auth_service"]);
std::string body = R"({"token":")" + token + R"("})";
// body << R"({"token":")" << token << R"("})";
httplib::Result res = cli.Post("/api/access", body, JSON_TYPE);
if (res->status == httplib::OK_200)
{
nlohmann::json resjson = nlohmann::json::parse(res->body);
if (resjson["access"] == "reject")
{
return false;
}
return true;
}
return false;
}