+# This file is part of FNP-Redakcja, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
import cgi
from django.contrib.auth.decorators import login_required
-from django.core.urlresolvers import reverse
+from django.urls import reverse
from django.http import HttpResponseRedirect, HttpResponse
import oauth2
raise Exception("Invalid response %s." % resp['status'])
request_token = dict(cgi.parse_qsl(content))
-
+
conn = OAuthConnection.get(request.user, beta)
# this might reset existing auth!
conn.access = 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)
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")
+ _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))
conn.access = True