Source code for bokeh.server.views.auth_request_handler
#-----------------------------------------------------------------------------# Copyright (c) Anaconda, Inc., and Bokeh Contributors.# All rights reserved.## The full license is in the file LICENSE.txt, distributed with this software.#-----------------------------------------------------------------------------''' Provide a mixin class to add authorization hooks to a request handler.'''#-----------------------------------------------------------------------------# Boilerplate#-----------------------------------------------------------------------------from__future__importannotationsimportlogging# isort:skiplog=logging.getLogger(__name__)#-----------------------------------------------------------------------------# Imports#-----------------------------------------------------------------------------# External importsfromtornado.webimportRequestHandler#-----------------------------------------------------------------------------# Globals and constants#-----------------------------------------------------------------------------__all__=('AuthRequestHandler',)#-----------------------------------------------------------------------------# General API#-----------------------------------------------------------------------------#-----------------------------------------------------------------------------# Dev API#-----------------------------------------------------------------------------
[docs]classAuthRequestHandler(RequestHandler):''' This mixin adds the expected Tornado authorization hooks: * get_login_url * get_current_user * prepare All of these delegate to the a :class:`~bokeh.serve.auth_provider.AuthProvider` configured on the Bokeh tornado application. '''
[docs]defget_login_url(self):''' Delegates to``get_login_url`` method of the auth provider, or the ``login_url`` attribute. '''ifself.application.auth_provider.get_login_urlisnotNone:returnself.application.auth_provider.get_login_url(self)ifself.application.auth_provider.login_urlisnotNone:returnself.application.auth_provider.login_urlraiseRuntimeError('login_url or get_login_url() must be supplied when authentication hooks are enabled')
[docs]defget_current_user(self):''' Delegate to the synchronous ``get_user`` method of the auth provider '''ifself.application.auth_provider.get_userisnotNone:returnself.application.auth_provider.get_user(self)return"default_user"
[docs]asyncdefprepare(self):''' Async counterpart to ``get_current_user`` '''ifself.application.auth_provider.get_user_asyncisnotNone:self.current_user=awaitself.application.auth_provider.get_user_async(self)