mirror of
				https://github.com/Telecominfraproject/wlan-cloud-ucentralsec.git
				synced 2025-10-30 18:27:49 +00:00 
			
		
		
		
	Adding oauth processing to retrieve the logged in user information.
This commit is contained in:
		| @@ -23,6 +23,7 @@ namespace uCentral { | |||||||
| 			return; | 			return; | ||||||
|  |  | ||||||
| 		try { | 		try { | ||||||
|  |             ParseParameters(Request); | ||||||
| 			if (Request.getMethod() == Poco::Net::HTTPServerRequest::HTTP_POST) { | 			if (Request.getMethod() == Poco::Net::HTTPServerRequest::HTTP_POST) { | ||||||
| 				// Extract the info for login... | 				// Extract the info for login... | ||||||
| 				Poco::JSON::Parser parser; | 				Poco::JSON::Parser parser; | ||||||
| @@ -32,7 +33,6 @@ namespace uCentral { | |||||||
| 				auto password = GetS(uCentral::RESTAPI::Protocol::PASSWORD, Obj); | 				auto password = GetS(uCentral::RESTAPI::Protocol::PASSWORD, Obj); | ||||||
| 				auto newPassword = GetS(uCentral::RESTAPI::Protocol::NEWPASSWORD, Obj); | 				auto newPassword = GetS(uCentral::RESTAPI::Protocol::NEWPASSWORD, Obj); | ||||||
|  |  | ||||||
|                 ParseParameters(Request); |  | ||||||
|                 if(GetBoolParameter("requirements",false)) { |                 if(GetBoolParameter("requirements",false)) { | ||||||
|                     Poco::JSON::Object  Answer; |                     Poco::JSON::Object  Answer; | ||||||
|                     Answer.set("passwordPattern",AuthService()->PasswordValidationExpression()); |                     Answer.set("passwordPattern",AuthService()->PasswordValidationExpression()); | ||||||
| @@ -86,8 +86,21 @@ namespace uCentral { | |||||||
| 				} else { | 				} else { | ||||||
| 					NotFound(Request, Response); | 					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 { | 			} else { | ||||||
| 				BadRequest(Request, Response, "Unsupported HTTP method."); |                 BadRequest(Request, Response, "Unsupported HTTP method."); | ||||||
| 			} | 			} | ||||||
| 			return; | 			return; | ||||||
| 		} catch (const Poco::Exception &E) { | 		} catch (const Poco::Exception &E) { | ||||||
|   | |||||||
| @@ -18,6 +18,7 @@ namespace uCentral { | |||||||
| 			: RESTAPIHandler(bindings, L, | 			: RESTAPIHandler(bindings, L, | ||||||
| 							 std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST, | 							 std::vector<std::string>{Poco::Net::HTTPRequest::HTTP_POST, | ||||||
| 													  Poco::Net::HTTPRequest::HTTP_DELETE, | 													  Poco::Net::HTTPRequest::HTTP_DELETE, | ||||||
|  |                                                       Poco::Net::HTTPRequest::HTTP_GET, | ||||||
| 													  Poco::Net::HTTPRequest::HTTP_OPTIONS}, | 													  Poco::Net::HTTPRequest::HTTP_OPTIONS}, | ||||||
| 													  Internal) {} | 													  Internal) {} | ||||||
| 		void handleRequest(Poco::Net::HTTPServerRequest &request, | 		void handleRequest(Poco::Net::HTTPServerRequest &request, | ||||||
|   | |||||||
| @@ -118,6 +118,12 @@ logout() { | |||||||
|   rm -rf token.json |   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() { | listendpoints() { | ||||||
|     curl  ${FLAGS} -X GET "https://${UCENTRALSEC}/api/v1/systemEndpoints" \ |     curl  ${FLAGS} -X GET "https://${UCENTRALSEC}/api/v1/systemEndpoints" \ | ||||||
|         -H "accept: application/json" \ |         -H "accept: application/json" \ | ||||||
| @@ -241,6 +247,7 @@ case "$1" in | |||||||
|     "deleteuser") login; deleteuser "$2" ; logout;; |     "deleteuser") login; deleteuser "$2" ; logout;; | ||||||
|     "getuser") login; getuser "$2" ; logout;; |     "getuser") login; getuser "$2" ; logout;; | ||||||
|     "listusers") login; listusers ; logout ;; |     "listusers") login; listusers ; logout ;; | ||||||
|  |     "me") login; me ; logout ;; | ||||||
|     "listendpoints") login; listendpoints ; logout ;; |     "listendpoints") login; listendpoints ; logout ;; | ||||||
|     "testlogin") testlogin "$2" "$3" "$4";; |     "testlogin") testlogin "$2" "$3" "$4";; | ||||||
|     "emailtest") emailtest "$2";; |     "emailtest") emailtest "$2";; | ||||||
| @@ -250,7 +257,6 @@ case "$1" in | |||||||
|     "getavatar") login; getavatar "$2"; logout;; |     "getavatar") login; getavatar "$2"; logout;; | ||||||
|     "deleteavatar") login; deleteavatar "$2"; logout;; |     "deleteavatar") login; deleteavatar "$2"; logout;; | ||||||
|     "help") login; help  ; logout ;; |     "help") login; help  ; logout ;; | ||||||
|  |  | ||||||
|     *) help ;; |     *) help ;; | ||||||
| esac | esac | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 stephb9959
					stephb9959