]> git.openstreetmap.org Git - osqa.git/commitdiff
adding a new setting that allows to automatically redirect the user's browser to...
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sun, 29 May 2011 15:54:07 +0000 (15:54 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Sun, 29 May 2011 15:54:07 +0000 (15:54 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1054 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum_modules/oauthauth/consumer.py
forum_modules/oauthauth/settings.py

index bf16a5415c6e12faec769baf184ca3dd62d2afa1..1d04aa2d9af26d314aea2b536f0dfc17061b24c2 100644 (file)
@@ -3,9 +3,12 @@ import urllib2
 import httplib
 import time
 
 import httplib
 import time
 
+from forum.settings import APP_URL
 from forum.authentication.base import AuthenticationConsumer, InvalidAuthentication
 from django.utils.translation import ugettext as _
 from forum.authentication.base import AuthenticationConsumer, InvalidAuthentication
 from django.utils.translation import ugettext as _
+from django.core.urlresolvers import reverse
 
 
+from settings import TWITTER_AUTO_CALLBACK_REDIRECT
 from lib import oauth2
 
 class OAuthAbstractAuthConsumer(AuthenticationConsumer):
 from lib import oauth2
 
 class OAuthAbstractAuthConsumer(AuthenticationConsumer):
@@ -46,7 +49,16 @@ class OAuthAbstractAuthConsumer(AuthenticationConsumer):
         return {}
         
     def fetch_request_token(self):
         return {}
         
     def fetch_request_token(self):
-        oauth_request = oauth2.Request.from_consumer_and_token(self.consumer, http_url=self.request_token_url)
+        parameters = {}
+        # If the installation is configured to automatically redirect to the Twitter provider done page -- do it.
+        if bool(TWITTER_AUTO_CALLBACK_REDIRECT):
+            callback_url = '%s%s' % (APP_URL, reverse('auth_provider_done', kwargs={ 'provider' : 'twitter', }))
+            # Pass
+            parameters.update({
+                'oauth_callback' : callback_url,
+            })
+
+        oauth_request = oauth2.Request.from_consumer_and_token(self.consumer, http_url=self.request_token_url, parameters=parameters)
         oauth_request.sign_request(self.signature_method, self.consumer, None)
         params = oauth_request
         data = urllib.urlencode(params)
         oauth_request.sign_request(self.signature_method, self.consumer, None)
         params = oauth_request
         data = urllib.urlencode(params)
@@ -81,7 +93,7 @@ class OAuthAbstractAuthConsumer(AuthenticationConsumer):
 
         url = oauth_request.to_url()
         connection = httplib.HTTPSConnection(self.server_url)
 
         url = oauth_request.to_url()
         connection = httplib.HTTPSConnection(self.server_url)
-        connection.request(oauth_request.http_method, url)
+        connection.request("GET", url)
 
         return connection.getresponse().read()
 
 
         return connection.getresponse().read()
 
index 7e9ef8c6f3741c8f9b51c13f31eed8029ff818b3..4977d013712e0df981eb92f6e0acf8dd386c3143 100644 (file)
@@ -1,19 +1,25 @@
 from forum.settings import EXT_KEYS_SET
 from forum.settings.base import Setting
 from forum.settings import EXT_KEYS_SET
 from forum.settings.base import Setting
+from django.utils.translation import ugettext_lazy as _
 
 TWITTER_CONSUMER_KEY = Setting('TWITTER_CONSUMER_KEY', '', EXT_KEYS_SET, dict(
 
 TWITTER_CONSUMER_KEY = Setting('TWITTER_CONSUMER_KEY', '', EXT_KEYS_SET, dict(
-label = "Twitter consumer key",
-help_text = """
+label = _("Twitter consumer key"),
+help_text = _("""
 Get this key at the <a href="http://twitter.com/apps/">Twitter apps</a> to enable
 authentication in your site through Twitter.
 Get this key at the <a href="http://twitter.com/apps/">Twitter apps</a> to enable
 authentication in your site through Twitter.
-""",
+"""),
 required=False))
 
 TWITTER_CONSUMER_SECRET = Setting('TWITTER_CONSUMER_SECRET', '', EXT_KEYS_SET, dict(
 required=False))
 
 TWITTER_CONSUMER_SECRET = Setting('TWITTER_CONSUMER_SECRET', '', EXT_KEYS_SET, dict(
-label = "Twitter consumer secret",
-help_text = """
+label = _("Twitter consumer secret"),
+help_text = _("""
 This your Twitter consumer secret that you'll get in the same place as the consumer key.
 This your Twitter consumer secret that you'll get in the same place as the consumer key.
-""",
+"""),
 required=False))
 
 required=False))
 
-
+TWITTER_AUTO_CALLBACK_REDIRECT = Setting('TWITTER_AUTO_CALLBACK_REDIRECT', True, EXT_KEYS_SET, dict(
+label = _("Twitter auto-callback redirect"),
+help_text = _("""
+Automatically redirect to the Twitter authentication done page, pass the oauth_callback parameter.
+"""),
+required=False))