Skip to content

Commit

Permalink
- find date
Browse files Browse the repository at this point in the history
- set expires on access_token cookie
  • Loading branch information
mhekkel committed Jan 22, 2024
1 parent d0598b6 commit ae62f5e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ if(ZEEP_BUILD_LIBRARY)
configure_file(${PROJECT_SOURCE_DIR}/cmake/asio.hpp.in ${PROJECT_SOURCE_DIR}/include/zeep/http/asio.hpp @ONLY)
endif()

find_package(date 3.0.1 QUIET NAMES libhowardhinnant-date)
find_package(date 3.0.1 QUIET NAMES date libhowardhinnant-date)

if(NOT date_FOUND)
if(ZEEP_ALLOW_FETCH_CONTENT)
Expand Down
20 changes: 16 additions & 4 deletions lib-http/src/security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ security_context::security_context(const std::string &secret, user_service &user
: m_secret(secret)
, m_users(users)
, m_default_allow(defaultAccessAllowed)
, m_default_jwt_exp(date::years{1})
, m_default_jwt_exp(date::years{ 1 })
{
register_password_encoder<pbkdf2_sha256_password_encoder>();
}
Expand Down Expand Up @@ -96,8 +96,8 @@ void security_context::validate_request(request &req) const
using namespace std::chrono;

auto exp = credentials["exp"].as<int64_t>();
auto exp_t = time_point<system_clock>() + seconds{exp};
auto exp_t = time_point<system_clock>() + seconds{ exp };

if (system_clock::now() > exp_t)
break; // expired

Expand Down Expand Up @@ -184,7 +184,19 @@ void security_context::add_authorization_headers(reply &rep, const user_details
auto h2 = encode_base64url(credentials.as<std::string>());
auto h3 = encode_base64url(hmac_sha256(h1 + '.' + h2, m_secret));

rep.set_cookie("access_token", h1 + '.' + h2 + '.' + h3, { { "HttpOnly", "" }, { "SameSite", "Lax" } });
std::stringstream s;
const std::time_t now_t = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now() + exp);
s << std::put_time(std::localtime(&now_t), "%a, %d %b %Y %H:%M:%S GMT");

rep.set_cookie("access_token", h1 + '.' + h2 + '.' + h3,
// clang-format off
{
{ "HttpOnly", "" },
{ "SameSite", "Lax" },
{ "Expires", '"' + s.str() + '"' }
}
// clang-format on
);
}

void security_context::add_authorization_headers(reply &rep, const user_details user)
Expand Down

0 comments on commit ae62f5e

Please sign in to comment.