support JSON response from auth, token endpoints
For example, the micropub.rocks auth endpoint only returns JSON-encoded responses. This implementation wraps all top-level values in the JSON object in an array to match the behavior of `parse_qs` but does not check to see if the value is already an array.
This commit is contained in:
parent
0471a3aeb8
commit
9f7bc5530b
|
@ -206,7 +206,10 @@ class MicropubClient:
|
||||||
'Flask-Micropub: auth response: %d - %s', response.status_code,
|
'Flask-Micropub: auth response: %d - %s', response.status_code,
|
||||||
response.text)
|
response.text)
|
||||||
|
|
||||||
rdata = parse_qs(response.text)
|
try:
|
||||||
|
rdata = dict((k,[v]) for (k,v) in response.json().items())
|
||||||
|
except ValueError:
|
||||||
|
rdata = parse_qs(response.text)
|
||||||
if response.status_code < 200 or response.status_code >= 300:
|
if response.status_code < 200 or response.status_code >= 300:
|
||||||
error_vals = rdata.get('error')
|
error_vals = rdata.get('error')
|
||||||
error_descs = rdata.get('error_description')
|
error_descs = rdata.get('error_description')
|
||||||
|
@ -276,7 +279,10 @@ class MicropubClient:
|
||||||
error='bad response from token endpoint: {}'
|
error='bad response from token endpoint: {}'
|
||||||
.format(token_response))
|
.format(token_response))
|
||||||
|
|
||||||
tdata = parse_qs(token_response.text)
|
try:
|
||||||
|
tdata = dict((k,[v]) for (k,v) in token_response.json().items())
|
||||||
|
except ValueError:
|
||||||
|
tdata = parse_qs(token_response.text)
|
||||||
if 'access_token' not in tdata:
|
if 'access_token' not in tdata:
|
||||||
return AuthResponse(
|
return AuthResponse(
|
||||||
me=me,
|
me=me,
|
||||||
|
|
Loading…
Reference in New Issue