Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

DEV -- AUTH SERVER BASE IN AUTH REQUEST #11

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/slic3r/Utils/PrintagoServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,15 @@ bool PrintagoDirector::ProcessPrintagoCommand(const PrintagoCommand& cmd)
if (!commandType.compare("meta")) {
if (!action.compare("init")) {
std::string token = parameters["token"];
std::string url_base = parameters.find("url_base") != parameters.end() && !parameters["url_base"].empty() ?
Http::url_decode(parameters["url_base"]) :
"http://localhost:3000";
if (token.empty()) {
PostErrorMessage("", "", cmd.GetOriginalCommand(), "Unauthorized: No Token");
return false;
}

if (ValidateToken(token)) {
if (ValidateToken(token, url_base)) {
server->get_session()->set_authorized(true);
actionDetail = "Authorized";
} else {
Expand Down Expand Up @@ -1296,9 +1299,10 @@ void PrintagoDirector::OnPrintJobSent(wxString printerId, bool success)
PostSuccessMessage(PBJob::printerId, "start_print_bbl", PBJob::command, wxString::Format("print sent to: %s", printerId));
}

bool PrintagoDirector::ValidateToken(const std::string& token)
bool PrintagoDirector::ValidateToken(const std::string& token, const std::string& url_base)
{
std::string url = "http://localhost:3000/api/slicer-tokens/" + token;

std::string url = url_base + "/api/slicer-tokens/" + token;
bool isValid = false;

// Perform the HTTP GET request synchronously
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/Utils/PrintagoServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class PrintagoDirector
bool SavePrintagoFile(const wxString url, wxFileName& localPath);
bool DownloadFileFromURL(const wxString url, const wxFileName& localPath);

bool ValidateToken(const std::string& token);
bool ValidateToken(const std::string& token, const std::string& url_base);
};

//``````````````````````````````````````````````````
Expand Down