holgern/beem

SteemConnect expects double quotes in JSON

Closed this issue · 3 comments

Expected behavior

The URL created from a transaction via steemconnect.url_from_tx() should be able to create the according transaction via SteemConnect.

Actual behavior

Parts of the JSON values are wrapped in single quotes (e.g. 'value') instead of double quotes (e.g. "value"), leading to JSON parsing errors with the created steemconnect link

How to reproduce

from beem import Steem
from beem.steemconnect import SteemConnect
s = Steem(nobroadcast=True, unsigned=True)
sc = SteemConnect(steem_instance=s)
tx = s.custom_json("123", {'field1': 'data1', 'field2': 'data2'}, required_posting_auths=["stmdev"])
print(sc.url_from_tx(tx))

Result:

https://v2.steemconnect.com/sign/custom_json?required_auths=%5B%5D&required_posting_auths=%5B%27stmdev%27%5D&id=123&json=%7B%22field1%22%3A+%22data1%22%2C+%22field2%22%3A+%22data2%22%7D

Note the %27=' around stmdev, but %22=" around the actual payload.

screenshot_2018-07-18_16-53-14

By modifying the URL to replace all %27 with %22 the URL works:

https://steemconnect.com/sign/custom_json?required_auths=%5B%5D&required_posting_auths=%5B%22stmdev%22%5D&id=123&json=%7B%22field1%22%3A+%22data1%22%2C+%22field2%22%3A+%22data2%22%7D

screenshot_2018-07-18_16-54-41

gregory-f from steemconnect confirmed that the "pure JSON" / SteemConnect expects double quotes.

Environment

  • beem 0.19.49
  • python 3.6.5

After doing some research, I fixed the issue by a simple:

params = urlencode(params).replace("%27", "%22")

Hope this will work for all cases. (It fixes the example).

will certainly work for 99% of the cases, but this also replaces single quotes in the payload:

from beem import Steem
from beem.steemconnect import SteemConnect
s = Steem(nobroadcast=True, unsigned=True)
sc = SteemConnect(steem_instance=s)
tx = s.custom_json("123", {'field1': "data with 'quotes'", 'field2': 'data2'}, required_posting_auths=["stmdev"])
print(sc.url_from_tx(tx))
https://v2.steemconnect.com/sign/custom_json?required_auths=%5B%5D&required_posting_auths=%5B%22stmdev%22%5D&id=123&json=%7B%22field1%22%3A+%22data+with+%22quotes%22%22%2C+%22field2%22%3A+%22data2%22%7D

edit: how about something in this direction:

--- ../beem/beem/steemconnect.py	2018-07-09 11:45:05.225750506 +0200
+++ steemconnect.py	2018-07-20 11:04:03.327834612 +0200
@@ -289,6 +289,9 @@
         if redirect_uri is not None:
             params.update({"redirect_uri": redirect_uri})
 
+        for key in params:
+            if isinstance(params[key], list):
+                params[key] = json.dumps(params[key])
         params = urlencode(params)
         url = urljoin(base_url, "sign/%s" % operation)
         url += "?" + params

this seems to work at least for that case, but I'm not sure it'll do for any...

Thanks, I will use your solution, looks cleaner.