summaryrefslogtreecommitdiff
path: root/subprojects/battleNetApi/src/token.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/battleNetApi/src/token.cpp')
-rw-r--r--subprojects/battleNetApi/src/token.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/subprojects/battleNetApi/src/token.cpp b/subprojects/battleNetApi/src/token.cpp
index b1ec5bf..056d80f 100644
--- a/subprojects/battleNetApi/src/token.cpp
+++ b/subprojects/battleNetApi/src/token.cpp
@@ -1,6 +1,7 @@
#include "token.hpp"
#include <chrono>
#include <curl/curl.h>
+#include <format>
#include <fstream>
#include <iostream>
#include <regex>
@@ -34,8 +35,12 @@ void Token::refreshToken() const {
}
void Token::writeNewTokenToFile() const {
- std::string aToken{getValidTokenWithApi()};
- writeTokenToFile(aToken);
+ const std::string kUser{"2b50f1123b424d5e9c21971a110fdd04"};
+ const std::string kPassword{"MrMkhVMNdOeqPL4Q4XVQAsRPR14J7Yq6"};
+ std::string aToken{getValidTokenWithApi(kUser, kPassword)};
+ if (not aToken.empty()) {
+ writeTokenToFile(aToken);
+ }
}
void Token::writeTokenToFile(const std::string &iToken) const {
@@ -44,7 +49,7 @@ void Token::writeTokenToFile(const std::string &iToken) const {
token_file << iToken << " " << expires_at.count() << '\n';
}
-std::string Token::getValidTokenWithApi() const {
+std::string Token::getValidTokenWithApi(const std::string &iUser, const std::string &iPassword) const {
CURL *curl = curl_easy_init();
std::string token_info;
if (curl) {
@@ -53,9 +58,7 @@ std::string Token::getValidTokenWithApi() const {
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curlCallbackStringOutput);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &token_info);
- curl_easy_setopt(curl, CURLOPT_USERPWD,
- "2b50f1123b424d5e9c21971a110fdd04:"
- "MrMkhVMNdOeqPL4Q4XVQAsRPR14J7Yq6");
+ curl_easy_setopt(curl, CURLOPT_USERPWD, std::format("{}:{}", iUser, iPassword).data());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
CURLcode result_code;
result_code = curl_easy_perform(curl);