diff --git a/fandjango/settings.py b/fandjango/settings.py index 27a5460..a1611f3 100644 --- a/fandjango/settings.py +++ b/fandjango/settings.py @@ -37,4 +37,4 @@ FANDJANGO_CACHE_SIGNED_REQUEST = getattr(settings, 'FACEBOOK_SIGNED_REQUEST_COOKIE', True) # A string describing the website URL. -FANDJANGO_SITE_URL = getattr(settings, 'FANDJANGO_SITE_URL') +FANDJANGO_SITE_URL = getattr(settings, 'FANDJANGO_SITE_URL', None) diff --git a/fandjango/utils.py b/fandjango/utils.py index 10ef91c..ba4e8e4 100644 --- a/fandjango/utils.py +++ b/fandjango/utils.py @@ -76,7 +76,10 @@ def authorization_denied_view(request): return authorization_denied_view(request) def get_post_authorization_redirect_url(request, canvas=True): - """Determine the URL users should be redirected to upon authorization the application.""" + """ + Determine the URL users should be redirected to upon authorization the application. + If request is non-canvas use user defined site url if set, else the site hostname. + """ path = request.get_full_path() @@ -90,8 +93,13 @@ def get_post_authorization_redirect_url(request, canvas=True): 'path': path } else: - path = path.replace(urlparse(FANDJANGO_SITE_URL).path, '') - redirect_uri = FANDJANGO_SITE_URL + path + if FANDJANGO_SITE_URL: + site_url = FANDJANGO_SITE_URL + path = path.replace(urlparse(site_url).path, '') + else: + protocol = "https" if request.is_secure() else "http" + site_url = "%s://%s" % (protocol, request.get_host()) + redirect_uri = site_url + path return redirect_uri diff --git a/tests/project/settings.py b/tests/project/settings.py index 7a3fd1d..5bca446 100644 --- a/tests/project/settings.py +++ b/tests/project/settings.py @@ -20,8 +20,6 @@ FACEBOOK_APPLICATION_NAMESPACE = 'fandjango-test' FACEBOOK_APPLICATION_CANVAS_URL = 'http://example.org/foo' -FANDJANGO_SITE_URL = FACEBOOK_APPLICATION_CANVAS_URL - SECRET_KEY = '123' USE_TZ = True diff --git a/tests/test_fandjango.py b/tests/test_fandjango.py index 69839cb..aa68cf6 100644 --- a/tests/test_fandjango.py +++ b/tests/test_fandjango.py @@ -566,8 +566,8 @@ def test_get_post_authorization_redirect_url(self): """ request = request_factory.get('/foo/bar/baz') redirect_url = get_post_authorization_redirect_url(request, canvas = False) - - assert redirect_url == 'http://example.org/foo/bar/baz' + # RequestFactory has the hostname "testserver" + assert redirect_url == 'http://testserver/foo/bar/baz' def test_querystring_removal(self): """