Source

django-publicauth / publicauth / backends / oauth.py

Diff from to

publicauth/backends/oauth.py

 from oauth.oauth import OAuthConsumer, OAuthToken, OAuthRequest, OAuthSignatureMethod_HMAC_SHA1
 
 from django.conf import settings as global_settings
+from django.utils.datastructures import MultiValueDictKeyError
 from django.core.urlresolvers import reverse
+from django.contrib import messages
 
 from annoying.exceptions import Redirect
 
 from publicauth.backends import BaseBackend
+from publicauth import lang
 
 
 class OAuthBackend(BaseBackend):
     def validate(self, request, data):
         signature_method = OAuthSignatureMethod_HMAC_SHA1()
         consumer = OAuthConsumer(self.CONSUMER_KEY, self.CONSUMER_SECRET)
-        oauth_token = data['oauth_token']
-        oauth_verifier = data['oauth_verifier']
+        try:
+            oauth_token = data['oauth_token']
+            oauth_verifier = data['oauth_verifier']
+        except MultiValueDictKeyError:
+            messages.add_message(request, messages.ERROR, lang.BACKEND_ERROR)
+            raise Redirect('publicauth-login')
         oauth_req = OAuthRequest.from_consumer_and_token(consumer, http_url=self.ACCESS_TOKEN_URL)
         oauth_req.set_parameter('oauth_token', oauth_token)
         oauth_req.set_parameter('oauth_verifier', oauth_verifier)
     def get_extra_data(self, response):
         return urlparse.parse_qs(response, keep_blank_values=False)
 
-    def extract_data(self, extra, field):
-        try:
-            return {self.PROFILE_MAPPING[field][0]: extra.get(field, '')[0]}
-        except IndexError:
-            return {self.PROFILE_MAPPING[field][0]: ''}
+    def extract_data(self, extra, backend_field, form_field):
+        return {form_field: extra.get(backend_field, '')[0]}