HaikuDepot: Only authorize requests where needed.
No requests are implemented yet which need to identify a user (such as rating a package).
This commit is contained in:
@@ -300,7 +300,7 @@ WebAppInterface::RetrievePackageInfo(const BString& packageName,
|
|||||||
.EndArray()
|
.EndArray()
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
return _SendJsonRequest("pkg", jsonString, message);
|
return _SendJsonRequest("pkg", jsonString, false, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -332,7 +332,7 @@ WebAppInterface::RetrieveBulkPackageInfo(const StringList& packageNames,
|
|||||||
.EndArray()
|
.EndArray()
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
return _SendJsonRequest("pkg", jsonString, message);
|
return _SendJsonRequest("pkg", jsonString, false, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -385,7 +385,7 @@ WebAppInterface::RetrieveUserRatings(const BString& packageName,
|
|||||||
.EndArray()
|
.EndArray()
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
return _SendJsonRequest("userrating", jsonString, message);
|
return _SendJsonRequest("userrating", jsonString, false, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@ WebAppInterface::RequestCaptcha(BMessage& message)
|
|||||||
.EndArray()
|
.EndArray()
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
return _SendJsonRequest("captcha", jsonString, message);
|
return _SendJsonRequest("captcha", jsonString, false, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -471,7 +471,7 @@ WebAppInterface::CreateUser(const BString& nickName,
|
|||||||
|
|
||||||
BString jsonString = builder.End();
|
BString jsonString = builder.End();
|
||||||
|
|
||||||
return _SendJsonRequest("user", jsonString, message);
|
return _SendJsonRequest("user", jsonString, false, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -491,7 +491,7 @@ WebAppInterface::AuthenticateUser(const BString& nickName,
|
|||||||
.EndArray()
|
.EndArray()
|
||||||
.End();
|
.End();
|
||||||
|
|
||||||
return _SendJsonRequest("user", jsonString, message);
|
return _SendJsonRequest("user", jsonString, false, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -500,7 +500,7 @@ WebAppInterface::AuthenticateUser(const BString& nickName,
|
|||||||
|
|
||||||
status_t
|
status_t
|
||||||
WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
||||||
BMessage& reply) const
|
bool needsAuthorization, BMessage& reply) const
|
||||||
{
|
{
|
||||||
BString urlString("https://depot.haiku-os.org/api/v1/");
|
BString urlString("https://depot.haiku-os.org/api/v1/");
|
||||||
urlString << domain;
|
urlString << domain;
|
||||||
@@ -515,8 +515,10 @@ WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString,
|
|||||||
|
|
||||||
BHttpRequest request(url, true, "HTTP", &listener, &context);
|
BHttpRequest request(url, true, "HTTP", &listener, &context);
|
||||||
|
|
||||||
// Authentication
|
// Authentication via Basic Authentication
|
||||||
if (!fUsername.IsEmpty() && !fPassword.IsEmpty()) {
|
// The other way would be to obtain a token and then use the Token Bearer
|
||||||
|
// header.
|
||||||
|
if (needsAuthorization && !fUsername.IsEmpty() && !fPassword.IsEmpty()) {
|
||||||
request.SetUserName(fUsername);
|
request.SetUserName(fUsername);
|
||||||
request.SetPassword(fPassword);
|
request.SetPassword(fPassword);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,8 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
status_t _SendJsonRequest(const char* domain,
|
status_t _SendJsonRequest(const char* domain,
|
||||||
BString jsonString, BMessage& reply) const;
|
BString jsonString, bool needsAuthorization,
|
||||||
|
BMessage& reply) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BString fUsername;
|
BString fUsername;
|
||||||
|
|||||||
Reference in New Issue
Block a user