make_singleuser_app: patch-in HubAuthenticatedHandler at lower priority

apply patch directly to BaseHandler instead of each handler instance
so that overrides can still take effect (i.e. APIHandler raising 403 instead of redirecting)
This commit is contained in:
Min RK
2021-01-28 12:20:35 +01:00
parent 1d9795c577
commit d3147f3fb7
4 changed files with 49 additions and 9 deletions

View File

@@ -19,6 +19,7 @@ import string
import time
import uuid
import warnings
from unittest import mock
from urllib.parse import quote
from urllib.parse import urlencode
@@ -832,8 +833,12 @@ class HubAuthenticated(object):
# add state argument to OAuth url
state = self.hub_auth.set_state_cookie(self, next_url=self.request.uri)
login_url = url_concat(login_url, {'state': state})
app_log.debug("Redirecting to login url: %s", login_url)
return login_url
# override at setting level,
# to allow any subclass overrides of get_login_url to preserve their effect
# for example, APIHandler raises 403 to prevent redirects
with mock.patch.dict(self.application.settings, {"login_url": login_url}):
app_log.debug("Redirecting to login url: %s", login_url)
return super().get_login_url()
def check_hub_user(self, model):
"""Check whether Hub-authenticated user or service should be allowed.