blob: 273871ef9d3e85ddb072fec0349c8ac73168608c [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Paul Fertser29aab242024-06-12 19:28:47 +00003#pragma once
4
5#include "http_response.hpp"
6#include "sessions.hpp"
7
Ed Tanousd7857202025-01-28 15:32:26 -08008#include <boost/beast/http/field.hpp>
9
Paul Fertser29aab242024-06-12 19:28:47 +000010namespace bmcweb
11{
12
13inline void setSessionCookies(crow::Response& res,
14 const persistent_data::UserSession& session)
15{
16 res.addHeader(boost::beast::http::field::set_cookie,
17 "XSRF-TOKEN=" + session.csrfToken +
18 "; Path=/; SameSite=Strict; Secure");
19 res.addHeader(boost::beast::http::field::set_cookie,
Gunnar Millsc76f9642025-01-26 21:37:59 -060020 "BMCWEB-SESSION=" + session.sessionToken +
Paul Fertser29aab242024-06-12 19:28:47 +000021 "; Path=/; SameSite=Strict; Secure; HttpOnly");
22}
23
24inline void clearSessionCookies(crow::Response& res)
25{
26 res.addHeader(boost::beast::http::field::set_cookie,
Gunnar Millsc76f9642025-01-26 21:37:59 -060027 "BMCWEB-SESSION="
Paul Fertser29aab242024-06-12 19:28:47 +000028 "; Path=/; SameSite=Strict; Secure; HttpOnly; "
29 "expires=Thu, 01 Jan 1970 00:00:00 GMT");
30 res.addHeader("Clear-Site-Data", R"("cache","cookies","storage")");
31}
32
33} // namespace bmcweb