data structure described in the API documentation * * @param string $serverKey The server key we need to encode data * @param mixed $data The data to encode, typically a string, array or object * * @return string The encapsulated data * * @see https://www.akeebabackup.com/documentation/json-api/ar01s02s02.html * * @throws \RuntimeException When the server capabilities don't match the requested encapsulation * @throws \InvalidArgumentException When $data cannot be converted to JSON */ public function encode($serverKey, $data) { return $data; } /** * Checks if the request body authorises the user to use the API. Each encapsulation can implement its own * authorisation method. This method is only called after the request body has been successfully decoded, therefore * encrypted encapsulations can simply return true. * * @param string $serverKey The server key we need to check the authorisation * @param array $body The decoded body (as returned by the decode() method) * * @return bool True if authorised */ public function isAuthorised($serverKey, $body) { $authenticated = false; if (isset($body['challenge']) && (strpos($body['challenge'], ':') >= 2) && (strlen($body['challenge']) >= 3)) { list ($challengeData, $providedHash) = explode(':', $body['challenge']); $computedHash = strtolower(md5($challengeData . $serverKey)); $authenticated = ($computedHash == $providedHash); } return $authenticated; } }