diff options
| -rw-r--r-- | subprojects/battleNetApi/include/token.hpp | 2 | ||||
| -rw-r--r-- | subprojects/battleNetApi/src/token.cpp | 15 |
2 files changed, 10 insertions, 7 deletions
diff --git a/subprojects/battleNetApi/include/token.hpp b/subprojects/battleNetApi/include/token.hpp index e135d3f..0b66f53 100644 --- a/subprojects/battleNetApi/include/token.hpp +++ b/subprojects/battleNetApi/include/token.hpp @@ -14,7 +14,7 @@ class Token { void refreshToken() const; void writeNewTokenToFile() const; void writeTokenToFile(const std::string &iToken) const; - std::string getValidTokenWithApi() const; + std::string getValidTokenWithApi(const std::string &iUser, const std::string &iPassword) const; std::chrono::seconds getCurrentTime() const; std::string extractFirstMatchRegex(const std::string &t_str, const std::string &t_regex) const; static size_t curlCallbackStringOutput(void *t_contents, size_t t_size, size_t t_nmemb, std::string *t_s); 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); |
