MCPcopy Create free account
hub / github.com/IppClub/Dora-SSR / has_valid_auth

Function has_valid_auth

Source/Http/HttpServer.cpp:396–422  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

394}
395
396static bool has_valid_auth(const httplib::Request& req, const std::string& token) {
397 auto it = req.headers.find("X-Dora-Auth"s);
398 if (it != req.headers.end() && it->second == token) {
399 return true;
400 }
401 it = req.headers.find("Authorization"s);
402 if (it != req.headers.end()) {
403 const std::string& auth = it->second;
404 if (auth == token) {
405 return true;
406 }
407 const std::string bearer = "Bearer "s;
408 if (auth.rfind(bearer, 0) == 0 && auth.substr(bearer.size()) == token) {
409 return true;
410 }
411 const std::string dora = "Dora "s;
412 if (auth.rfind(dora, 0) == 0 && auth.substr(dora.size()) == token) {
413 return true;
414 }
415 }
416 for (const auto& param : req.params) {
417 if (param.first == "auth"s && param.second == token) {
418 return true;
419 }
420 }
421 return false;
422}
423
424static void set_unauthorized(httplib::Response& res) {
425 res.status = 401;

Callers 1

isAuthorizedMethod · 0.85

Calls 4

findMethod · 0.65
substrMethod · 0.65
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected