diff --git a/build b/build index c793025..301160a 100644 --- a/build +++ b/build @@ -1 +1 @@ -7 \ No newline at end of file +8 \ No newline at end of file diff --git a/src/RESTAPI_oauth2Handler.cpp b/src/RESTAPI_oauth2Handler.cpp index b61055f..54b6e54 100644 --- a/src/RESTAPI_oauth2Handler.cpp +++ b/src/RESTAPI_oauth2Handler.cpp @@ -23,6 +23,7 @@ namespace uCentral { return; try { + ParseParameters(Request); if (Request.getMethod() == Poco::Net::HTTPServerRequest::HTTP_POST) { // Extract the info for login... Poco::JSON::Parser parser; @@ -32,7 +33,6 @@ namespace uCentral { auto password = GetS(uCentral::RESTAPI::Protocol::PASSWORD, Obj); auto newPassword = GetS(uCentral::RESTAPI::Protocol::NEWPASSWORD, Obj); - ParseParameters(Request); if(GetBoolParameter("requirements",false)) { Poco::JSON::Object Answer; Answer.set("passwordPattern",AuthService()->PasswordValidationExpression()); @@ -86,8 +86,21 @@ namespace uCentral { } else { NotFound(Request, Response); } + } else if (Request.getMethod() == Poco::Net::HTTPServerRequest::HTTP_GET) { + if (!IsAuthorized(Request, Response)) { + UnAuthorized(Request, Response, "Not authorized."); + return; + } + bool GetMe = GetBoolParameter("me",false); + if(GetMe) { + Poco::JSON::Object Me; + UserInfo_.userinfo.to_json(Me); + ReturnObject(Request, Me, Response); + return; + } + BadRequest(Request, Response); } else { - BadRequest(Request, Response, "Unsupported HTTP method."); + BadRequest(Request, Response, "Unsupported HTTP method."); } return; } catch (const Poco::Exception &E) { diff --git a/src/RESTAPI_oauth2Handler.h b/src/RESTAPI_oauth2Handler.h index ddc401a..732eacc 100644 --- a/src/RESTAPI_oauth2Handler.h +++ b/src/RESTAPI_oauth2Handler.h @@ -18,6 +18,7 @@ namespace uCentral { : RESTAPIHandler(bindings, L, std::vector{Poco::Net::HTTPRequest::HTTP_POST, Poco::Net::HTTPRequest::HTTP_DELETE, + Poco::Net::HTTPRequest::HTTP_GET, Poco::Net::HTTPRequest::HTTP_OPTIONS}, Internal) {} void handleRequest(Poco::Net::HTTPServerRequest &request, diff --git a/test_scripts/curl/cli b/test_scripts/curl/cli index 15332ff..5cfd34c 100755 --- a/test_scripts/curl/cli +++ b/test_scripts/curl/cli @@ -118,6 +118,12 @@ logout() { rm -rf token.json } +me() { + curl ${FLAGS} -X GET -H "Content-Type: application/json" \ + -H "Authorization: Bearer ${token}" \ + "https://${UCENTRALSEC}/api/v1/oauth2?me=true" +} + listendpoints() { curl ${FLAGS} -X GET "https://${UCENTRALSEC}/api/v1/systemEndpoints" \ -H "accept: application/json" \ @@ -241,6 +247,7 @@ case "$1" in "deleteuser") login; deleteuser "$2" ; logout;; "getuser") login; getuser "$2" ; logout;; "listusers") login; listusers ; logout ;; + "me") login; me ; logout ;; "listendpoints") login; listendpoints ; logout ;; "testlogin") testlogin "$2" "$3" "$4";; "emailtest") emailtest "$2";; @@ -250,7 +257,6 @@ case "$1" in "getavatar") login; getavatar "$2"; logout;; "deleteavatar") login; deleteavatar "$2"; logout;; "help") login; help ; logout ;; - *) help ;; esac