X-Git-Url: https://git.mdrn.pl/redakcja.git/blobdiff_plain/edf56edfdbea88b0e18c2e5aecbb6e62250ec3d7..94da7eb2739d91e80607681bc61672ef769ca90c:/src/apiclient/views.py?ds=inline diff --git a/src/apiclient/views.py b/src/apiclient/views.py index 8d0a7983..666ef481 100644 --- a/src/apiclient/views.py +++ b/src/apiclient/views.py @@ -1,4 +1,7 @@ -import cgi +# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. +# +from urllib.parse import parse_qsl from django.contrib.auth.decorators import login_required from django.urls import reverse @@ -21,8 +24,8 @@ def oauth(request, beta=False): if resp['status'] != '200': raise Exception("Invalid response %s." % resp['status']) - request_token = dict(cgi.parse_qsl(content)) - + request_token = dict(parse_qsl(content.decode('utf-8'))) + conn = OAuthConnection.get(request.user, beta) # this might reset existing auth! conn.access = False @@ -31,10 +34,10 @@ def oauth(request, beta=False): conn.save() url = "%s?oauth_token=%s&oauth_callback=%s" % ( - WL_AUTHORIZE_URL if not beta else BETA_AUTHORIZE_URL, - request_token['oauth_token'], - request.build_absolute_uri(reverse("apiclient_oauth_callback" if not beta else "apiclient_beta_callback")), - ) + WL_AUTHORIZE_URL if not beta else BETA_AUTHORIZE_URL, + request_token['oauth_token'], + request.build_absolute_uri(reverse("apiclient_oauth_callback" if not beta else "apiclient_beta_callback")), + ) return HttpResponseRedirect(url) @@ -49,8 +52,8 @@ def oauth_callback(request, beta=False): token = oauth2.Token(conn.token, conn.token_secret) token.set_verifier(oauth_verifier) client = oauth2.Client(wl_consumer, token) - resp, content = client.request(WL_ACCESS_TOKEN_URL if not beta else BETA_ACCESS_TOKEN_URL, method="POST") - access_token = dict(cgi.parse_qsl(content)) + _resp, content = client.request(WL_ACCESS_TOKEN_URL if not beta else BETA_ACCESS_TOKEN_URL, method="POST") + access_token = dict(parse_qsl(content.decode('utf-8'))) conn.access = True conn.token = access_token['oauth_token']