Vladimir Mihailenco avatar Vladimir Mihailenco committed f256d08

Fix query handling for non-http urls

Comments (0)

Files changed (1)

oauth_provider/models.py

 import uuid
 import urllib
-import urlparse
 from time import time
 import oauth2 as oauth
 
 
 generate_random = User.objects.make_random_password
 
+
 class Nonce(models.Model):
     token_key = models.CharField(max_length=KEY_SIZE)
     consumer_key = models.CharField(max_length=CONSUMER_KEY_SIZE)
     key = models.CharField(max_length=255)
-    
+
     def __unicode__(self):
         return u"Nonce %s for %s" % (self.key, self.consumer_key)
 
     name = models.CharField(max_length=255)
     url = models.TextField(max_length=MAX_URL_LENGTH)
     is_readonly = models.BooleanField(default=True)
-    
+
     objects = ResourceManager()
 
     def __unicode__(self):
 class Consumer(models.Model):
     name = models.CharField(max_length=255)
     description = models.TextField()
-    
+
     key = models.CharField(max_length=CONSUMER_KEY_SIZE)
     secret = models.CharField(max_length=SECRET_SIZE, blank=True)
 
     user = models.ForeignKey(User, null=True, blank=True)
 
     objects = ConsumerManager()
-        
+
     def __unicode__(self):
         return u"Consumer %s with key %s" % (self.name, self.key)
 
     REQUEST = 1
     ACCESS = 2
     TOKEN_TYPES = ((REQUEST, u'Request'), (ACCESS, u'Access'))
-    
+
     key = models.CharField(max_length=KEY_SIZE, null=True, blank=True)
     secret = models.CharField(max_length=SECRET_SIZE, null=True, blank=True)
     token_type = models.SmallIntegerField(choices=TOKEN_TYPES)
     timestamp = models.IntegerField(default=long(time()))
     is_approved = models.BooleanField(default=False)
-    
-    user = models.ForeignKey(User, null=True, blank=True, related_name='tokens')
+
+    user = models.ForeignKey(User, null=True, blank=True,
+                             related_name='tokens')
     consumer = models.ForeignKey(Consumer)
     resource = models.ForeignKey(Resource)
-    
+
     ## OAuth 1.0a stuff
     verifier = models.CharField(max_length=VERIFIER_SIZE)
-    callback = models.CharField(max_length=MAX_URL_LENGTH, null=True, blank=True)
+    callback = models.CharField(max_length=MAX_URL_LENGTH, null=True,
+                                blank=True)
     callback_confirmed = models.BooleanField(default=False)
-    
+
     objects = TokenManager()
-    
+
     def __unicode__(self):
-        return u"%s Token %s for %s" % (self.get_token_type_display(), self.key, self.consumer)
+        return u"%s Token %s for %s" % (self.get_token_type_display(),
+                                        self.key, self.consumer)
 
     def to_string(self, only_key=False):
         token_dict = {
-            'oauth_token': self.key, 
+            'oauth_token': self.key,
             'oauth_token_secret': self.secret,
             'oauth_callback_confirmed': self.callback_confirmed and 'true' or 'error'
         }
 
     def generate_random_codes(self):
         """
-        Used to generate random key/secret pairings. 
-        Use this after you've added the other data in place of save(). 
+        Used to generate random key/secret pairings.
+        Use this after you've added the other data in place of save().
         """
         self.key = uuid.uuid4().hex
         self.secret = generate_random(length=SECRET_SIZE)
         OAuth 1.0a, append the oauth_verifier.
         """
         if self.callback and self.verifier:
-            parts = urlparse.urlparse(self.callback)
-            scheme, netloc, path, params, query, fragment = parts[:6]
-            if query:
-                query = '%s&oauth_verifier=%s' % (query, self.verifier)
+            query = 'oauth_verifier=%s' % self.verifier
+            if '?' in self.callback:
+                query = '&' + query
             else:
-                query = 'oauth_verifier=%s' % self.verifier
-            return urlparse.urlunparse((scheme, netloc, path, params,
-                query, fragment))
+                query = '?' + query
+            return self.callback + query
         return self.callback
 
     def set_callback(self, callback):
-        if callback != OUT_OF_BAND: # out of band, says "we can't do this!"
+        if callback != OUT_OF_BAND:  # out of band, says "we can't do this!"
             if check_valid_callback(callback):
                 self.callback = callback
                 self.callback_confirmed = True
                 self.save()
             else:
                 raise oauth.Error('Invalid callback URL.')
-        
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 ProjectModifiedEvent.java.
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.