token: use an http header for the token
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "../headers/xforwardfor.hpp"
|
||||
#include "../headers/gitProtocolHeader.hpp"
|
||||
#include "../headers/acceptLanguageHeader.hpp"
|
||||
#include "../headers/setCookieHeader.hpp"
|
||||
#include "../debug/log.hpp"
|
||||
#include "../GlobalState.hpp"
|
||||
#include "../config/Config.hpp"
|
||||
@@ -344,6 +345,8 @@ void CServerHandler::challengeSubmitted(const Pistache::Http::Request& req, Pist
|
||||
resp.success = true;
|
||||
resp.token = TOKEN;
|
||||
|
||||
response.headers().add(std::make_shared<SetCookieHeader>("CheckpointToken=" + TOKEN + "; HttpOnly; Path=/; Secure; SameSite=Lax"));
|
||||
|
||||
response.send(Pistache::Http::Code::Ok, glz::write_json(resp).value());
|
||||
}
|
||||
|
||||
|
||||
26
src/headers/setCookieHeader.hpp
Normal file
26
src/headers/setCookieHeader.hpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <pistache/http_headers.h>
|
||||
#include <pistache/net.h>
|
||||
|
||||
class SetCookieHeader : public Pistache::Http::Header::Header {
|
||||
public:
|
||||
NAME("Set-Cookie");
|
||||
|
||||
SetCookieHeader(const std::string& cookie = "") : m_cookie(cookie) {
|
||||
;
|
||||
}
|
||||
|
||||
void parse(const std::string& str) override {
|
||||
m_cookie = str;
|
||||
}
|
||||
|
||||
void write(std::ostream& os) const override {
|
||||
os << m_cookie;
|
||||
}
|
||||
|
||||
std::string from() const {
|
||||
return m_cookie;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string m_cookie = "";
|
||||
};
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "headers/cfHeader.hpp"
|
||||
#include "headers/gitProtocolHeader.hpp"
|
||||
#include "headers/acceptLanguageHeader.hpp"
|
||||
#include "headers/setCookieHeader.hpp"
|
||||
|
||||
#include "debug/log.hpp"
|
||||
|
||||
@@ -76,6 +77,7 @@ int main(int argc, char** argv, char** envp) {
|
||||
Pistache::Http::Header::Registry::instance().registerHeader<XForwardedForHeader>();
|
||||
Pistache::Http::Header::Registry::instance().registerHeader<GitProtocolHeader>();
|
||||
Pistache::Http::Header::Registry::instance().registerHeader<AcceptLanguageHeader>();
|
||||
Pistache::Http::Header::Registry::instance().registerHeader<SetCookieHeader>();
|
||||
|
||||
g_pDB = std::make_unique<CDatabase>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user