def unauthorized(message="Unauthorized: You do not have access to this resource.", *, err=None, default=None):
"""
If in debug mode: show detailed error.
If not in debug: return a 401 Unauthorized and a WWW-Authenticate header to trigger the browser auth dialog.
"""
from bottle import response
debug_enabled = bool(getattr(gw, "debug", False))
if debug_enabled:
return view_debug_error(
title="401 Unauthorized",
message=message,
err=err,
status=401,
default=default
)
# 401 with auth header = browser will prompt for password
response.status = 401
response.headers['WWW-Authenticate'] = 'Basic realm="GWAY"'
response.content_type = "text/plain"
return message