This commit is contained in:
parent
253978bc5f
commit
65fc484fa4
@ -39,30 +39,37 @@ auto server::check_authorization(const httplib::Request &req) -> bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto authorization = req.get_header_value("Authorization");
|
||||
auto authorization = req.get_header_value("Authorization");
|
||||
if (authorization.empty()) {
|
||||
utils::error::raise_error(function_name, "Authorization header is not set");
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto auth_parts = utils::string::split(authorization, ' ', true);
|
||||
auto auth_parts = utils::string::split(authorization, ' ', true);
|
||||
if (auth_parts.empty()) {
|
||||
utils::error::raise_error(function_name, "Authorization header is empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto auth_type = auth_parts[0U];
|
||||
auto auth_type = auth_parts[0U];
|
||||
if (auth_type != "Basic") {
|
||||
utils::error::raise_error(function_name, "Authorization is not Basic");
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto data = macaron::Base64::Decode(authorization.substr(6U));
|
||||
const auto auth =
|
||||
utils::string::split(std::string(data.begin(), data.end()), ':', true);
|
||||
if (auth.size() != 2U) {
|
||||
auto data = macaron::Base64::Decode(authorization.substr(6U));
|
||||
auto auth_str = std::string(data.begin(), data.end());
|
||||
|
||||
auto auth = utils::string::split(auth_str, ':', true);
|
||||
if (auth.size() < 2U) {
|
||||
utils::error::raise_error(function_name, "Authorization is not valid");
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto &user = auth[0U];
|
||||
const auto &pwd = auth[1U];
|
||||
auto user = auth.at(0U);
|
||||
auth.erase(auth.begin());
|
||||
|
||||
auto pwd = utils::string::join(auth, ':');
|
||||
return (user == config_.get_api_user()) && (pwd == config_.get_api_auth());
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user