From 09712c1a19191a0d11afb33462850d2c03bb7ad7 Mon Sep 17 00:00:00 2001 From: netkas Date: Fri, 13 Sep 2024 13:46:31 -0400 Subject: [PATCH] Add Authenticate class for handling authentication logic --- .../Classes/StandardMethods/Authenticate.php | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/Socialbox/Classes/StandardMethods/Authenticate.php diff --git a/src/Socialbox/Classes/StandardMethods/Authenticate.php b/src/Socialbox/Classes/StandardMethods/Authenticate.php new file mode 100644 index 0000000..b3eaf19 --- /dev/null +++ b/src/Socialbox/Classes/StandardMethods/Authenticate.php @@ -0,0 +1,50 @@ +getParameters()['type'])) + { + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Missing required parameter \'type\''); + } + + if(strlen($rpcRequest->getParameters()['type']) == 0) + { + return $rpcRequest->produceError(StandardError::RPC_INVALID_ARGUMENTS, 'Parameter \'type\' cannot be empty'); + } + + return match (FirstLevelAuthentication::tryFrom($rpcRequest->getParameters()['type'])) + { + FirstLevelAuthentication::PASSWORD => self::handlePassword($request), + + default => $rpcRequest->produceError(StandardError::UNSUPPORTED_AUTHENTICATION_TYPE, + sprintf('Unsupported authentication type: %s', $rpcRequest->getParameters()['type']) + ), + }; + } + + /** + * Handles the password authentication phase for the peer + * + * @param ClientRequest $request + * @return SerializableInterface + */ + private static function handlePassword(ClientRequest $request): SerializableInterface + { + + } +} \ No newline at end of file