фича: автообновление сессии

This commit is contained in:
2025-01-17 19:09:44 +03:00
parent a4214fd007
commit 3537965393
16 changed files with 170 additions and 96 deletions

View File

@@ -6,7 +6,10 @@
namespace http::auth::jwt {
extern std::string secretKey;
constexpr const char* EMPTY_AUTH_COOKIE = "auth=;Path=/; Max-Age=86400; HttpOnly; SameSite=Lax";;
constexpr const char* EMPTY_AUTH_COOKIE = "auth=;Path=/; Max-Age=86400; HttpOnly; SameSite=Lax";
constexpr int64_t SESSION_LIVE_MS = 24 * 60 * 60 * 1000; // 24 часа
constexpr int64_t SESSION_UPDATE_THRESHOLD = 10 * 60 * 1000; // 10 минут
void generateSecretKey();
@@ -17,6 +20,7 @@ namespace http::auth::jwt {
*/
class Jwt {
std::string payload;
int64_t lastUpdate = 0;
std::string signature;
public:
static Jwt fromCookies(const std::string& cookie);
@@ -26,7 +30,9 @@ namespace http::auth::jwt {
std::string getUsername();
std::string asCookie();
std::string asCookie(bool isSecure = false);
bool needUpdate() const;
~Jwt();
};