From 2581b6b0da3c056d6662752bee34069359fb18d7 Mon Sep 17 00:00:00 2001 From: emeric Date: Fri, 6 Oct 2023 22:59:35 +0200 Subject: [PATCH] Updated deprecated cookie handling --- src/lms/ui/Auth.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lms/ui/Auth.cpp b/src/lms/ui/Auth.cpp index 95646614..3cacfd1f 100644 --- a/src/lms/ui/Auth.cpp +++ b/src/lms/ui/Auth.cpp @@ -21,12 +21,12 @@ #include +#include #include +#include #include #include -#include #include -#include #include "services/auth/IAuthTokenService.hpp" #include "services/auth/IPasswordService.hpp" @@ -50,16 +50,12 @@ void createAuthToken(Database::UserId userId, const Wt::WDateTime& expiry) { const std::string secret {Service<::Auth::IAuthTokenService>::get()->createAuthToken(userId, expiry)}; + Wt::Http::Cookie cookie{ authCookieName, secret, expiry }; + cookie.setSecure(LmsApp->environment().urlScheme() == "https"); - LmsApp->setCookie(authCookieName, - secret, - expiry.toTime_t() - Wt::WDateTime::currentDateTime().toTime_t(), - "", - "", - LmsApp->environment().urlScheme() == "https"); + LmsApp->setCookie(cookie); } - std::optional processAuthToken(const Wt::WEnvironment& env) { @@ -72,8 +68,12 @@ processAuthToken(const Wt::WEnvironment& env) { case ::Auth::IAuthTokenService::AuthTokenProcessResult::State::Denied: case ::Auth::IAuthTokenService::AuthTokenProcessResult::State::Throttled: - LmsApp->setCookie(authCookieName, std::string {}, 0, "", "", env.urlScheme() == "https"); + { + Wt::Http::Cookie cookie{ authCookieName }; + cookie.setSecure(LmsApp->environment().urlScheme() == "https"); + LmsApp->removeCookie(cookie); return std::nullopt; + } case ::Auth::IAuthTokenService::AuthTokenProcessResult::State::Granted: createAuthToken(res.authTokenInfo->userId, res.authTokenInfo->expiry);