From 480090ebe494ed3fdb19732ac0dd3b194da4039f Mon Sep 17 00:00:00 2001 From: Marty McGuire Date: Thu, 9 Mar 2017 22:18:20 -0500 Subject: [PATCH 1/3] Include `response_type` in initial auth parameters micropub.rocks client tests die on initial authorization if `response_type=code` is not included in the original parameters --- flask_micropub.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flask_micropub.py b/flask_micropub.py index 6394ac4..b97f13a 100644 --- a/flask_micropub.py +++ b/flask_micropub.py @@ -135,6 +135,7 @@ class MicropubClient: 'me': me, 'client_id': self.client_id, 'redirect_uri': redirect_url, + 'response_type': 'code', 'state': '{}|{}'.format(csrf_token, state or ''), } if scope: From 0471a3aeb89e82f4887caf625cc61f82ee428e8b Mon Sep 17 00:00:00 2001 From: Marty McGuire Date: Thu, 9 Mar 2017 22:32:19 -0500 Subject: [PATCH 2/3] Add `grant_type` to authorization token requests micropub.rocks fails on the token fetching step if `grant_type=authorization_code` is missing from the token request. --- flask_micropub.py | 1 + 1 file changed, 1 insertion(+) diff --git a/flask_micropub.py b/flask_micropub.py index b97f13a..b11c47d 100644 --- a/flask_micropub.py +++ b/flask_micropub.py @@ -259,6 +259,7 @@ class MicropubClient: 'redirect_uri': redirect_uri, 'client_id': self.client_id, 'state': wrapped_state, + 'grant_type': 'authorization_code', } flask.current_app.logger.debug( 'Flask-Micropub: requesting access token from: %s, data: %s', From 9f7bc5530b296a36b457bed4b5021c666262d918 Mon Sep 17 00:00:00 2001 From: Marty McGuire Date: Thu, 9 Mar 2017 23:33:43 -0500 Subject: [PATCH 3/3] 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. --- flask_micropub.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/flask_micropub.py b/flask_micropub.py index b11c47d..647c235 100644 --- a/flask_micropub.py +++ b/flask_micropub.py @@ -206,7 +206,10 @@ class MicropubClient: 'Flask-Micropub: auth response: %d - %s', response.status_code, 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: error_vals = rdata.get('error') error_descs = rdata.get('error_description') @@ -276,7 +279,10 @@ class MicropubClient: error='bad response from token endpoint: {}' .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: return AuthResponse( me=me,