Compare commits
2 Commits
4aad60f69d
...
65fc484fa4
Author | SHA1 | Date | |
---|---|---|---|
65fc484fa4 | |||
253978bc5f |
@ -39,30 +39,37 @@ auto server::check_authorization(const httplib::Request &req) -> bool {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto authorization = req.get_header_value("Authorization");
|
auto authorization = req.get_header_value("Authorization");
|
||||||
if (authorization.empty()) {
|
if (authorization.empty()) {
|
||||||
|
utils::error::raise_error(function_name, "Authorization header is not set");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto auth_parts = utils::string::split(authorization, ' ', true);
|
auto auth_parts = utils::string::split(authorization, ' ', true);
|
||||||
if (auth_parts.empty()) {
|
if (auth_parts.empty()) {
|
||||||
|
utils::error::raise_error(function_name, "Authorization header is empty");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto auth_type = auth_parts[0U];
|
auto auth_type = auth_parts[0U];
|
||||||
if (auth_type != "Basic") {
|
if (auth_type != "Basic") {
|
||||||
|
utils::error::raise_error(function_name, "Authorization is not Basic");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto data = macaron::Base64::Decode(authorization.substr(6U));
|
auto data = macaron::Base64::Decode(authorization.substr(6U));
|
||||||
const auto auth =
|
auto auth_str = std::string(data.begin(), data.end());
|
||||||
utils::string::split(std::string(data.begin(), data.end()), ':', true);
|
|
||||||
if (auth.size() != 2U) {
|
auto auth = utils::string::split(auth_str, ':', true);
|
||||||
|
if (auth.size() < 2U) {
|
||||||
|
utils::error::raise_error(function_name, "Authorization is not valid");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto &user = auth[0U];
|
auto user = auth.at(0U);
|
||||||
const auto &pwd = auth[1U];
|
auth.erase(auth.begin());
|
||||||
|
|
||||||
|
auto pwd = utils::string::join(auth, ':');
|
||||||
return (user == config_.get_api_user()) && (pwd == config_.get_api_auth());
|
return (user == config_.get_api_user()) && (pwd == config_.get_api_auth());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ namespace repertory::cli::actions {
|
|||||||
const std::string &data_directory,
|
const std::string &data_directory,
|
||||||
const provider_type &prov,
|
const provider_type &prov,
|
||||||
const std::string &unique_id,
|
const std::string &unique_id,
|
||||||
std::string user, std::string password)
|
std::string user,
|
||||||
-> exit_code {
|
std::string password) -> exit_code {
|
||||||
lock_data lock(prov, unique_id);
|
lock_data lock(prov, unique_id);
|
||||||
const auto res = lock.grab_lock(1U);
|
const auto res = lock.grab_lock(1U);
|
||||||
if (res == lock_result::success) {
|
if (res == lock_result::success) {
|
||||||
|
Reference in New Issue
Block a user