database stuff
This commit is contained in:
+41
-34
@@ -1,20 +1,18 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <sstream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <cpr/cpr.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
//#include "models.h"
|
||||
#include "token_manager.h"
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
//extern "C"
|
||||
//{
|
||||
|
||||
|
||||
token_manager::token_manager()
|
||||
{
|
||||
@@ -22,51 +20,60 @@ token_manager::token_manager()
|
||||
|
||||
loginResult token_manager::retrieve_token()
|
||||
{
|
||||
auto cred = parse_auth_credentials();
|
||||
|
||||
loginResult lr;
|
||||
lr.access_token = "dsfdsf";
|
||||
lr.token_type = "demo";
|
||||
|
||||
return lr;
|
||||
}
|
||||
|
||||
auth_credentials token_manager::parse_auth_credentials()
|
||||
loginResult token_manager::retrieve_token(std::string_view path)
|
||||
{
|
||||
auth_credentials auth;
|
||||
//auto ss = working_path.string();
|
||||
//auto path = fs::canonical(fs::path("."));
|
||||
//std::cout << "canonical path " << path.string() << std::endl;
|
||||
|
||||
return auth;
|
||||
}
|
||||
|
||||
/**
|
||||
LoginRes* token_manager::retrieve_token(TokenReq *tok)
|
||||
{
|
||||
LoginRes *res = new LoginRes;
|
||||
auto cred = parse_auth_credentials(path);
|
||||
|
||||
nlohmann::json reqObj;
|
||||
reqObj["client_id"] = tok->ClientId;
|
||||
reqObj["client_secret"] = tok->ClientSecret;
|
||||
reqObj["audience"] = tok->Audience;
|
||||
reqObj["grant_type"] = tok->GrantType;
|
||||
reqObj["client_id"] = cred.client_id;
|
||||
reqObj["client_secret"] = cred.client_secret;
|
||||
reqObj["audience"] = cred.api_identifier;
|
||||
reqObj["grant_type"] = "client_credentials";
|
||||
|
||||
std::string uri{tok->URI};
|
||||
std::string uri{cred.uri};
|
||||
uri.append("/");
|
||||
uri.append(tok->Endpoint);
|
||||
uri.append(cred.endpoint);
|
||||
|
||||
auto r = cpr::Post(cpr::Url{uri},
|
||||
cpr::Body{reqObj.dump()},
|
||||
cpr::Header{{"Content-Type", "application/json"}});
|
||||
cpr::Header{{"Content-Type", "application/json"},
|
||||
{"Connection", "keep-alive"}});
|
||||
|
||||
auto post_res = nlohmann::json::parse(r.text);
|
||||
strcpy(res->Token, post_res["access_token"].get<std::string>().c_str());
|
||||
strcpy(res->TokenType, post_res["token_type"].get<std::string>().c_str());
|
||||
res->Expiration = post_res["expires_in"].get<int>();
|
||||
strcpy(res->Message, "Success");
|
||||
|
||||
return res;
|
||||
loginResult lr;
|
||||
lr.access_token = post_res["access_token"].get<std::string>();
|
||||
lr.token_type = post_res["token_type"].get<std::string>();
|
||||
lr.expiration = post_res["expires_in"].get<int>();
|
||||
|
||||
return lr;
|
||||
}
|
||||
|
||||
auth_credentials token_manager::parse_auth_credentials(std::string_view path)
|
||||
{
|
||||
auto exe_path = fs::canonical(path).parent_path().string();
|
||||
exe_path.append("/authcredentials.json");
|
||||
|
||||
std::fstream a(exe_path, std::ios::in);
|
||||
std::stringstream s;
|
||||
s << a.rdbuf();
|
||||
a.close();
|
||||
|
||||
auto con = nlohmann::json::parse(s.str());
|
||||
|
||||
auth_credentials auth;
|
||||
auth.uri = "https://";
|
||||
auth.uri.append(con["Domain"]);
|
||||
auth.api_identifier = con["ApiIdentifier"];
|
||||
auth.client_id = con["ClientId"];
|
||||
auth.client_secret = con["ClientSecret"];
|
||||
auth.endpoint = "oauth/token";
|
||||
|
||||
return auth;
|
||||
}
|
||||
*/
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user