commit 3c5a2b21eff4b35448ef4c8082522c0e79705358
Author: Kostas Papadimitriou <kpap@grnet.gr>
Date:   Fri May 31 13:34:47 2013 +0300

    astakos: Configurable third party provider endpoints
    
    not so often, but providers do seem to change urls

diff --git a/snf-astakos-app/astakos/im/views/target/google.py b/snf-astakos-app/astakos/im/views/target/google.py
index 6772e7b..c7fb2b6 100644
--- a/snf-astakos-app/astakos/im/views/target/google.py
+++ b/snf-astakos-app/astakos/im/views/target/google.py
@@ -32,35 +32,47 @@
 # or implied, of GRNET S.A.
 
 import json
+import logging
+import urllib
+import oauth2 as oauth
 
 from django.utils.translation import ugettext as _
 from django.contrib import messages
 from django.views.decorators.http import require_http_methods
 from django.http import HttpResponseRedirect
 from django.core.urlresolvers import reverse
+from django.conf import settings as django_settings
 
 from astakos.im.models import AstakosUser
 from astakos.im import settings
 from astakos.im.views.target import get_pending_key, \
-    handle_third_party_signup, handle_third_party_login, init_third_party_session
+    handle_third_party_signup, handle_third_party_login, \
+    init_third_party_session
 from astakos.im.views.decorators import cookie_fix, requires_auth_provider
 
-import logging
-import urllib
-
 logger = logging.getLogger(__name__)
-
-import oauth2 as oauth
-
 signature_method = oauth.SignatureMethod_HMAC_SHA1()
 
 OAUTH_CONSUMER_KEY = settings.GOOGLE_CLIENT_ID
 OAUTH_CONSUMER_SECRET = settings.GOOGLE_SECRET
 
-token_scope = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email'
-authenticate_url = 'https://accounts.google.com/o/oauth2/auth'
-access_token_url = 'https://www.googleapis.com/oauth2/v1/tokeninfo'
-request_token_url = 'https://accounts.google.com/o/oauth2/token'
+
+def django_setting(key, default):
+    return getattr(django_settings, 'GOOGLE_%s' % key.upper, default)
+
+default_token_scopes = ['https://www.googleapis.com/auth/userinfo.profile',
+                        'https://www.googleapis.com/auth/userinfo.email']
+
+token_scope = django_setting('token_scope', ' '.join(default_token_scopes))
+authenticate_url = django_setting(
+    'authenticate_url',
+    'https://accounts.google.com/o/oauth2/auth')
+access_token_url = django_setting(
+    'access_token_url',
+    'https://www.googleapis.com/oauth2/v1/tokeninfo')
+request_token_url = django_setting(
+    'request_token_url',
+    'https://accounts.google.com/o/oauth2/token')
 
 
 def get_redirect_uri():
diff --git a/snf-astakos-app/astakos/im/views/target/linkedin.py b/snf-astakos-app/astakos/im/views/target/linkedin.py
index 8419759..d8d7e1c 100644
--- a/snf-astakos-app/astakos/im/views/target/linkedin.py
+++ b/snf-astakos-app/astakos/im/views/target/linkedin.py
@@ -32,30 +32,40 @@
 # or implied, of GRNET S.A.
 
 import json
+import logging
+import oauth2 as oauth
+import cgi
 
 from django.contrib import messages
 from django.views.decorators.http import require_http_methods
 from django.http import HttpResponseRedirect
 from django.core.urlresolvers import reverse
+from django.conf import settings as django_settings
 
 from astakos.im.models import AstakosUser
 from astakos.im import settings
 from astakos.im.views.target import get_pending_key, \
-    handle_third_party_signup, handle_third_party_login, init_third_party_session
+    handle_third_party_signup, handle_third_party_login, \
+    init_third_party_session
 from astakos.im.views.decorators import cookie_fix, \
     requires_auth_provider
 
-import logging
-
 logger = logging.getLogger(__name__)
 
-import oauth2 as oauth
-import cgi
 
+def django_setting(key, default):
+    return getattr(django_settings, 'GOOGLE_%s' % key.upper, default)
 
-request_token_url      = 'https://api.linkedin.com/uas/oauth/requestToken?scope=r_basicprofile+r_emailaddress'
-access_token_url       = 'https://api.linkedin.com/uas/oauth/accessToken'
-authenticate_url       = 'https://www.linkedin.com/uas/oauth/authorize'
+token_scope = 'r_basicprofile+r_emailaddress'
+request_token_url = django_setting(
+    'request_token_url',
+    'https://api.linkedin.com/uas/oauth/requestToken?scope=' + token_scope)
+access_token_url = django_setting(
+    'access_token_url',
+    'https://api.linkedin.com/uas/oauth/accessToken')
+authenticate_url = django_setting(
+    'authenticate_url',
+    'https://www.linkedin.com/uas/oauth/authorize')
 
 
 @requires_auth_provider('linkedin')
diff --git a/snf-astakos-app/astakos/im/views/target/twitter.py b/snf-astakos-app/astakos/im/views/target/twitter.py
index 1b51603..d7591c4 100644
--- a/snf-astakos-app/astakos/im/views/target/twitter.py
+++ b/snf-astakos-app/astakos/im/views/target/twitter.py
@@ -32,11 +32,15 @@
 # or implied, of GRNET S.A.
 
 import logging
+import oauth2 as oauth
+import cgi
+import urllib
 
 from django.contrib import messages
 from django.views.decorators.http import require_http_methods
 from django.http import HttpResponseRedirect, urlencode
 from django.core.urlresolvers import reverse
+from django.conf import settings as django_settings
 
 from urlparse import urlunsplit, urlsplit, parse_qsl
 
@@ -47,16 +51,22 @@ from astakos.im.views.target import get_pending_key, \
     init_third_party_session
 from astakos.im.views.decorators import cookie_fix, requires_auth_provider
 
-
 logger = logging.getLogger(__name__)
 
-import oauth2 as oauth
-import cgi
-import urllib
 
-request_token_url = 'https://api.twitter.com/oauth/request_token'
-access_token_url = 'https://api.twitter.com/oauth/access_token'
-authenticate_url = 'https://api.twitter.com/oauth/authenticate'
+def django_setting(key, default):
+    return getattr(django_settings, 'TWITTER_%s' % key.upper, default)
+
+request_token_url = django_setting(
+    'request_token_url',
+    'https://api.twitter.com/oauth/request_token')
+access_token_url = django_setting(
+    'access_token_url',
+    'https://api.twitter.com/oauth/access_token')
+authenticate_url = django_setting(
+    'authenticate_url',
+    'https://api.twitter.com/oauth/authenticate')
+
 
 @requires_auth_provider('twitter')
 @require_http_methods(["GET", "POST"])
