Added Controller namespace
This commit is contained in:
@@ -57,6 +57,34 @@ Model::loginResult Manager::token_manager::retrieve_token(std::string_view path)
|
||||
|
||||
return lr;
|
||||
}
|
||||
Model::loginResult Manager::token_manager::retrieve_token(const Model::BinaryPath& bConf)
|
||||
{
|
||||
auto cred = parse_auth_credentials(bConf);
|
||||
|
||||
nlohmann::json reqObj;
|
||||
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{cred.uri};
|
||||
uri.append("/");
|
||||
uri.append(cred.endpoint);
|
||||
|
||||
auto r = cpr::Post(cpr::Url{uri},
|
||||
cpr::Body{reqObj.dump()},
|
||||
cpr::Header{{"Content-Type", "application/json"},
|
||||
{"Connection", "keep-alive"}});
|
||||
|
||||
auto post_res = nlohmann::json::parse(r.text);
|
||||
|
||||
Model::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;
|
||||
}
|
||||
|
||||
bool Manager::token_manager::is_token_valid(std::string& auth, Scope scope)
|
||||
{
|
||||
@@ -104,10 +132,10 @@ Model::auth_credentials Manager::token_manager::parse_auth_credentials(std::stri
|
||||
|
||||
return auth;
|
||||
}
|
||||
Model::auth_credentials Manager::token_manager::parse_auth_credentials(const BinaryPath& bConf)
|
||||
Model::auth_credentials Manager::token_manager::parse_auth_credentials(const Model::BinaryPath& bConf)
|
||||
{
|
||||
auto exePath = Manager::directory_manager::configPath(bConf);
|
||||
exe_path.append("/auth_credentials.json");
|
||||
exePath.append("/auth_credentials.json");
|
||||
|
||||
auto con = Manager::directory_manager::credentialConfigContent(exePath);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user