| 394 | } |
| 395 | |
| 396 | static 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 | |
| 424 | static void set_unauthorized(httplib::Response& res) { |
| 425 | res.status = 401; |
no test coverage detected