From 36171a48e74618c56ec3bf2dd64543eeb433e448 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stephan=20A=C3=9Fmus?= Date: Sun, 21 Sep 2014 00:17:25 +0200 Subject: [PATCH] HaikuDepot: Only authorize requests where needed. No requests are implemented yet which need to identify a user (such as rating a package). --- src/apps/haikudepot/WebAppInterface.cpp | 20 +++++++++++--------- src/apps/haikudepot/WebAppInterface.h | 3 ++- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/apps/haikudepot/WebAppInterface.cpp b/src/apps/haikudepot/WebAppInterface.cpp index 9e1189db3e..d8cc173f53 100644 --- a/src/apps/haikudepot/WebAppInterface.cpp +++ b/src/apps/haikudepot/WebAppInterface.cpp @@ -300,7 +300,7 @@ WebAppInterface::RetrievePackageInfo(const BString& packageName, .EndArray() .End(); - return _SendJsonRequest("pkg", jsonString, message); + return _SendJsonRequest("pkg", jsonString, false, message); } @@ -332,7 +332,7 @@ WebAppInterface::RetrieveBulkPackageInfo(const StringList& packageNames, .EndArray() .End(); - return _SendJsonRequest("pkg", jsonString, message); + return _SendJsonRequest("pkg", jsonString, false, message); } @@ -385,7 +385,7 @@ WebAppInterface::RetrieveUserRatings(const BString& packageName, .EndArray() .End(); - return _SendJsonRequest("userrating", jsonString, message); + return _SendJsonRequest("userrating", jsonString, false, message); } @@ -439,7 +439,7 @@ WebAppInterface::RequestCaptcha(BMessage& message) .EndArray() .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(); - return _SendJsonRequest("user", jsonString, message); + return _SendJsonRequest("user", jsonString, false, message); } @@ -491,7 +491,7 @@ WebAppInterface::AuthenticateUser(const BString& nickName, .EndArray() .End(); - return _SendJsonRequest("user", jsonString, message); + return _SendJsonRequest("user", jsonString, false, message); } @@ -500,7 +500,7 @@ WebAppInterface::AuthenticateUser(const BString& nickName, status_t WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString, - BMessage& reply) const + bool needsAuthorization, BMessage& reply) const { BString urlString("https://depot.haiku-os.org/api/v1/"); urlString << domain; @@ -515,8 +515,10 @@ WebAppInterface::_SendJsonRequest(const char* domain, BString jsonString, BHttpRequest request(url, true, "HTTP", &listener, &context); - // Authentication - if (!fUsername.IsEmpty() && !fPassword.IsEmpty()) { + // Authentication via Basic Authentication + // 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.SetPassword(fPassword); } diff --git a/src/apps/haikudepot/WebAppInterface.h b/src/apps/haikudepot/WebAppInterface.h index 1fe1b7cf79..3407b25f31 100644 --- a/src/apps/haikudepot/WebAppInterface.h +++ b/src/apps/haikudepot/WebAppInterface.h @@ -72,7 +72,8 @@ public: private: status_t _SendJsonRequest(const char* domain, - BString jsonString, BMessage& reply) const; + BString jsonString, bool needsAuthorization, + BMessage& reply) const; private: BString fUsername;