Commits

Benoit Chesneau committed 69de4a3

Use restkit oauth2 instead of python-oauth2

  • Participants
  • Parent commits 7834780

Comments (0)

Files changed (3)

oauthclient/models.py

 from django.db import models
-import oauth2
+import restkit.oauth2 as oauth
 
 KEY_SIZE = SECRET_SIZE = 16
 
         """Return a consumer object, configured with settings values.
         
         """
-        return oauth2.Consumer(self.key, self.secret)
+        return oauth.Consumer(self.key, self.secret)
     
     class Meta:
         get_latest_by = 'last_modification'

oauthclient/views.py

 from django.core.urlresolvers import reverse
 
 # oauth imports
-import oauth2
+from restkit import OAuthFilter, request as make_request
+import restkit.oauth2 as oauth
 import urlparse
 
 #oauthclient import
     
     """
     token = ConsumerToken.objects.get(identifier=identifier)
-    client = oauth2.Client(token.get_consumer())
-    resp, content = client.request(token.server.get_request_token_url(), "GET")
+    auth = OAuthFilter(('*', token.get_consumer()))
+    
+    resp = make_request(token.server.get_request_token_url(), filters=[auth])
 
-    if resp['status'] != '200':
-        raise Exception("Invalid response %s." % resp['status'])    
+    if resp.status_int != 200:
+        raise Exception("Invalid response %s." % resp.status)    
 
-    request_token = dict(urlparse.parse_qsl(content))
+    request_token = dict(urlparse.parse_qsl(resp.body))
     if not ('oauth_token' and 'oauth_token_secret' in request_token):
         raise Exception("Invalid response: oauth_token and oauth_token_secret have to be present in the OAuth server response")
     
     token = ConsumerToken.objects.get(identifier=identifier)
 
     # Echange the request token against a access token.
-    request_token = oauth2.Token(request.session[identifier + '_request_token'],
+    request_token = oauth.Token(request.session[identifier + '_request_token'],
         request.session[identifier + '_request_token_secret'])
     request_token.set_verifier(request.GET['oauth_verifier'])
-    client = oauth2.Client(token.get_consumer(), request_token)
-    resp, content = client.request(token.server.get_access_token_url() , "POST")
-    access_token = dict(urlparse.parse_qsl(content))
+    
+    auth = OAuthFilter(('*', token.get_consumer(), request_token))
+    resp  = make_request(token.server.get_access_token_url() , filters=[auth])
+    access_token = dict(urlparse.parse_qsl(resp.body))
     
     # test if access token is valid. 
     if not ('oauth_token' and 'oauth_token_secret' in access_token):
     url = 'http://bitbucket.org/bisonvert/django-oauthclient',
     install_requires = [
             "Django >= 1.1",
+            "restkit"
     ],
     classifiers=[
         'Development Status :: 4 - Beta',