offline avatar offline committed 51d7ac8

friendfeed added, but it doesnt work yet

Comments (0)

Files changed (3)


 from django.conf import settings as global_settings
 from django.utils.datastructures import MultiValueDictKeyError
 from django.core.urlresolvers import reverse
+from django.utils import simplejson
 from django.contrib import messages
 from annoying.exceptions import Redirect
     REQUEST_TOKEN_URL = property(lambda self: getattr(global_settings, "%s_REQUEST_TOKEN_URL" % self.provider.upper()))
     ACCESS_TOKEN_URL = property(lambda self: getattr(global_settings, "%s_ACCESS_TOKEN_URL" % self.provider.upper()))
     AUTHORIZE_URL = property(lambda self: getattr(global_settings, "%s_AUTHORIZE_URL" % self.provider.upper()))
+    API_URL = property(lambda self: getattr(global_settings, "%s_API_URL" % self.provider.upper()))
     def begin(self, request, data):
         oauth_req = OAuthRequest.from_consumer_and_token(consumer, token, http_url=self.AUTHORIZE_URL)
         oauth_req.sign_request(signature_method, consumer, token)
         raise Redirect(oauth_req.to_url())
     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']
+            oauth_verifier = data.get('oauth_verifier', None)
         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)
+        if 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.identity = urlparse.parse_qs(response, keep_blank_values=False)['oauth_token'][0]
         raise Redirect('publicauth-extra', self.provider)
     def get_extra_data(self, response):
-        return urlparse.parse_qs(response, keep_blank_values=False)
+        user_id = urlparse.parse_qs(response, keep_blank_values=False)['user_id'][0]
+        url = self.API_URL % user_id
+        return simplejson.loads(urllib.urlopen(url).read())
     def extract_data(self, extra, backend_field, form_field):
-        return {form_field: extra.get(backend_field, '')[0]}
+        return {form_field: extra.get(backend_field, '')}


     'openid': 'publicauth.backends.openid.OpenIDBackend',                                          #
     'google': '',                                          #
     'twitter': 'publicauth.backends.oauth.OAuthBackend',                                           #
+    'friendfeed': 'publicauth.backends.oauth.OAuthBackend',                                        #
     'facebook': 'publicauth.backends.facebook.FacebookBackend',                                    #
     }                                                                                              #
 )                                                                                                  #


 <a href="{% url publicauth-begin 'google' %}?openid_url={{ }}">Google</a>
 <a href="{% url publicauth-begin 'twitter' %}?next={{ }}">Twitter</a>
+<a href="{% url publicauth-begin 'friendfeed' %}?next={{ }}">FriendFeed</a>
 <a href="#" onclick="return fb_login();" id="facebook">Login with facebook</a>
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.