blob: 7107eb09c6b2c9051b1b7965c098bdf7708910f0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
#include <chrono>
#include <string>
class Token {
public:
Token(const std::string &iTokenFilePath);
std::string text() const;
const bool hasExpired() const;
void updateToken();
private:
const std::string mFilePath; //!< Path to the token file
const std::string mUsername; //!< Username for Battle.net API
const std::string mPassword; //!< Password for Battle.net API
std::string mToken; //!< Token value
/**
* @return An access token that a user can use to perform API requests.
* First, the cache file is checked.
* A new token is computed if the current token lifetime expired,
* or if there is no token at all.
*/
std::string generateToken();
void writeTokenToLocalFile(const std::pair<std::string, std::uint64_t> &iToken) const;
std::string getTokenFromLocalFile() const;
std::pair<std::string, std::uint64_t> getTokenWithApi() const;
std::chrono::seconds getCurrentTime() const;
static size_t curlCallbackStringOutput(void *iPtr, size_t iSize, size_t iNmemb, std::string *iUserData);
static const std::uint16_t kTokenContentMinLength{10};
};
|