Skip to content

Commit 98f8284

Browse files
authored
Merge pull request #4 from restreamio/api-auth-through-env-API_AUTH_TOKEN
feat: use env var API_AUTH_TOKEN instead of user pass for HTTP api auth
2 parents d85f829 + df70d59 commit 98f8284

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/controller/controller_api.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,15 @@ bool Controller::authorize(JSON::Value &Request, JSON::Value &Response, Socket::
134134
if (Request.isMember("authorize") && Request["authorize"]["username"].asString() != ""){
135135
std::string UserID = Request["authorize"]["username"];
136136
if (Storage["account"].isMember(UserID)){
137-
if (Secure::md5(Storage["account"][UserID]["password"].asString() + Challenge) ==
138-
Request["authorize"]["password"].asString()){
139-
Response["authorize"]["status"] = "OK";
140-
return true;
137+
char* pass = getenv("API_AUTH_TOKEN");
138+
if (pass) {
139+
std::string passStr = pass;
140+
if (Secure::md5(passStr) ==
141+
Secure::md5(Request["authorize"]["password"].asString())){
142+
143+
Response["authorize"]["status"] = "OK";
144+
return true;
145+
}
141146
}
142147
}
143148
if (Request["authorize"]["password"].asString() != ""){

0 commit comments

Comments
 (0)