diff --git a/gratipay/security/authentication/__init__.py b/gratipay/security/authentication/__init__.py new file mode 100644 index 0000000000..bb409a2f36 --- /dev/null +++ b/gratipay/security/authentication/__init__.py @@ -0,0 +1 @@ +from __future__ import absolute_import, division, print_function, unicode_literals diff --git a/gratipay/security/authentication.py b/gratipay/security/authentication/website_helpers.py similarity index 99% rename from gratipay/security/authentication.py rename to gratipay/security/authentication/website_helpers.py index 7dee71e79e..80801f8b7b 100644 --- a/gratipay/security/authentication.py +++ b/gratipay/security/authentication/website_helpers.py @@ -9,7 +9,6 @@ from gratipay.security.crypto import constant_time_compare from gratipay.security.user import User, SESSION - ANON = User() def _get_user_via_api_key(api_key): @@ -56,11 +55,6 @@ def _turn_off_csrf(request): request.headers.cookie['csrf_token'] = csrf_token request.headers['X-CSRF-TOKEN'] = csrf_token -def start_user_as_anon(): - """Make sure we always have a user object, regardless of exceptions during authentication. - """ - return {'user': ANON} - def authenticate_user_if_possible(request, user): """This signs the user in. """ @@ -86,3 +80,8 @@ def add_auth_to_response(response, request=None, user=ANON): if SESSION in request.headers.cookie: if not user.ANON: user.keep_signed_in(response.headers.cookie) + +def start_user_as_anon(): + """Make sure we always have a user object, regardless of exceptions during authentication. + """ + return {'user': ANON} diff --git a/gratipay/website.py b/gratipay/website.py index 5fb41c000f..fc5e4eddde 100644 --- a/gratipay/website.py +++ b/gratipay/website.py @@ -8,7 +8,8 @@ from aspen.website import Website as BaseWebsite from . import utils, security, typecasting, version -from .security import authentication, csrf +from .security import csrf +from .security.authentication import website_helpers as auth_helpers from .utils import erase_cookie, http_caching, i18n, set_cookie, set_version_header, timer from .renderers import csv_dump, jinja2_htmlescaped, eval_, scss from .models import team @@ -86,8 +87,8 @@ def modify_algorithm(self, tell_sentry): utils.use_tildes_for_participants, algorithm['redirect_to_base_url'], i18n.set_up_i18n, - authentication.start_user_as_anon, - authentication.authenticate_user_if_possible, + auth_helpers.start_user_as_anon, + auth_helpers.authenticate_user_if_possible, security.only_allow_certain_methods, csrf.extract_token_from_cookie, csrf.reject_forgeries, @@ -106,7 +107,7 @@ def modify_algorithm(self, tell_sentry): algorithm['get_response_for_exception'], set_version_header, - authentication.add_auth_to_response, + auth_helpers.add_auth_to_response, csrf.add_token_to_response, http_caching.add_caching_to_response, security.add_headers_to_response,