It looks to me like you're missing some base64 padding bytes at the end of your protected, payload, and signature strings: a double equals sign (==) at the end of the protected and signature, and a single equals sign (=) at the end of the payload.
Your base64 encoding library should generate these padding characters whenever they are required (this depends on the length of the input string to the base64 encoding process). You should make sure that whatever you're doing isn't somehow removing the = characters (where present) from the end of these base64 strings.
And the given version is using the former version rather than the latter version.
(2) Probably more importantly (?), the supposed n value is actually an entire PEM-encoded public key (!!) rather than just the modulus n. If you base64-decode it and run openssl rsa -inform der -pubin on it, you get the whole key object, not just the modulus n. You can see related to this that the given string ends in AQAB, which is duplicative of the modulus e given elsewhere in the JWK (but it's not sufficient to just chop that off, the entire encoding of n as DER is probably mistaken here).
The error messages above is a payload from an ACME Server.
The best way to develop ACME clients is:
Write functions that can property serialize and deserialize the payloads, and cover these with unit tests.
When the tests pass, start testing against a local server like Pebble or Boulder. Write integrated tests that cover a full certificate order and authorization process.
When the local tests pass, try testing against production systems like the Staging API.