django-publicauth / publicauth / backends /

Diff from to


 from oauth.oauth import OAuthConsumer, OAuthToken, OAuthRequest, OAuthSignatureMethod_HMAC_SHA1
 from django.conf import settings as global_settings
-from django.utils.translation import ugettext as _
 from django.core.urlresolvers import reverse
-from django.contrib.auth.models import User
-from django.contrib import auth
 from annoying.exceptions import Redirect
-from publicauth import settings
 from publicauth.backends import BaseBackend
-from publicauth.models import PublicID
 class TwitterBackend(BaseBackend):
     AUTHORIZE_URL = property(lambda self: getattr(global_settings, "%s_AUTHORIZE_URL" % self.provider.upper()))
     def begin(self, request, data):
+        """
+        Try to get Request Token from OAuth Provider and 
+        redirect user to provider's site for approval.
+        """
         consumer = OAuthConsumer(self.CONSUMER_KEY, self.CONSUMER_SECRET)
         signature_method = OAuthSignatureMethod_HMAC_SHA1()
-        callback = request.build_absolute_uri(reverse('publicauth-social-complete', args=[self.provider]))
+        callback = request.build_absolute_uri(reverse('publicauth-complete', args=[self.provider]))
         oauth_req = OAuthRequest.from_consumer_and_token(consumer, callback=callback, http_url=self.REQUEST_TOKEN_URL)
         oauth_req.sign_request(signature_method, consumer, None)
         response = urllib.urlopen(oauth_req.to_url()).read()
         raise Redirect(oauth_req.to_url())
-    def complete(self, request, response):
+    def validate(self, request, data):
         signature_method = OAuthSignatureMethod_HMAC_SHA1()
-        data = request.GET.copy()
         consumer = OAuthConsumer(self.CONSUMER_KEY, self.CONSUMER_SECRET)
         oauth_token = data['oauth_token']
         oauth_verifier = data['oauth_verifier']
         oauth_req.set_parameter('oauth_verifier', oauth_verifier)
         oauth_req.sign_request(signature_method, consumer, None)
         response = urllib.urlopen(oauth_req.to_url()).read()
-        self.set_identity(urlparse.parse_qs(response, keep_blank_values=False)['oauth_token'][0])
-        user = auth.authenticate(identity=self.get_identity(), provider=self.provider)
+        self.identity = urlparse.parse_qs(response, keep_blank_values=False)['oauth_token'][0]
+        return response
-        extra = self.get_extra_data(response)
-        data = self.set_profile_fields(request, extra)
+    def complete(self, request, response):
+        data = self.fill_extra_fields(request, self.get_extra_data(response))
         request.session['extra'] = data
-        request.session['identity'] = self.get_identity()
-        raise Redirect('publicauth-social-extra', self.provider)
+        request.session['identity'] = self.identity
+        raise Redirect('publicauth-extra', self.provider)
     def get_extra_data(self, response):
         return urlparse.parse_qs(response, keep_blank_values=False)
-    def extract_data(self, data, field):
+    def extract_data(self, extra, field):
-            return {self.PROFILE_MAPPING[field][0]: data.get(field, '')[0]}
+            return {self.PROFILE_MAPPING[field][0]: extra.get(field, '')[0]}
         except IndexError:
             return {self.PROFILE_MAPPING[field][0]: ''}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.