Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization checks in server.py #5386

Merged
merged 8 commits into from
Aug 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions panel/io/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,27 +485,28 @@ async def get(self, *args, **kwargs):
token = session.token
logger.info(LOG_SESSION_CREATED, id(session.document))
with set_curdoc(session.document):
import inspect
authorize_callback_signature = inspect.signature(config.authorize_callback)
authorize_callback_parameters = authorize_callback_signature.parameters
authorized = False
if len(authorize_callback_parameters) == 1:
authorized = config.authorize_callback(state.user_info)
if len(authorize_callback_parameters) == 2:
authorized = config.authorize_callback(state.user_info, self.request.path)
if config.authorize_callback and not authorized:
if config.auth_template:
with open(config.auth_template) as f:
template = _env.from_string(f.read())
else:
template = ERROR_TEMPLATE
page = template.render(
npm_cdn=config.npm_cdn,
title='Panel: Authorization Error',
error_type='Authorization Error',
error='User is not authorized.',
error_msg=f'{state.user} is not authorized to access this application.'
)
if config.authorize_callback:
import inspect
authorize_callback_signature = inspect.signature(config.authorize_callback)
authorize_callback_parameters = authorize_callback_signature.parameters
authorized = False
if len(authorize_callback_parameters) == 1:
authorized = config.authorize_callback(state.user_info)
if len(authorize_callback_parameters) == 2:
authorized = config.authorize_callback(state.user_info, self.request.path)
if not authorized:
philippjfr marked this conversation as resolved.
Show resolved Hide resolved
if config.auth_template:
with open(config.auth_template) as f:
template = _env.from_string(f.read())
else:
template = ERROR_TEMPLATE
page = template.render(
npm_cdn=config.npm_cdn,
title='Panel: Authorization Error',
error_type='Authorization Error',
error='User is not authorized.',
error_msg=f'{state.user} is not authorized to access this application.'
)
else:
resources = Resources.from_bokeh(self.application.resources())
page = server_html_page_for_session(
Expand Down