Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled
25 lines
660 B
C++
25 lines
660 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)
|
|
{
|
|
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;
|
|
}
|