ok()) { throw new \Exception('Could not fetch nonce from Matrix.'); } $nonce = $nonceResponse->json()['nonce']; // Generate MAC $mac = hash_hmac( 'sha1', $nonce."\0". $username."\0". $password."\0". 'notadmin', $secret ); // Send registration request $response = Http::post("$server/_synapse/admin/v1/register", [ 'nonce' => $nonce, 'username' => $username, 'password' => $password, 'admin' => false, 'mac' => $mac, ]); if ($response->failed()) { $error = $response->json()['error'] ?? $response->body(); throw new \Exception($error); } return $response->json(); } }