我有一个简单的bokeh服务器应用程序,我想在基于Linux的Azure节点上公开它。服务器在那里并且正在运行。
我的问题是:如何通过用户名和密码保护内容?我不需要用户的身份验证。
到目前为止,我的想法(未尝试过,可能没有用)
您可以尝试禁用bokeh服务器的会话ID的生成,并仅在用户身份验证之后才由外部应用程序生成会话ID :(
基于bokeh文档的这一部分)
bokeh secret
命令生成密钥:$散景秘密 oIWDL7DVYCaBJG9eYQ2Wvf2f2uhOAIM8xNS8Kds3eizV
BOKEH_SECRET_KEY
环境变量设置为生成值;$ export BOKEH_SECRET_KEY = oIWDL7DVYCaBJG9eYQ2Wvf2f2uhOAIM8xNS8Kds3eizV
$ export BOKEH_SIGN_SESSIONS =真实
--session-ids external-signed
参数运行bokeh服务器:$ bokeh服务myApp --session-ids外部签名
在此模式下,用户应提供有效(签名)的会话ID来访问bokeh服务器。
from functools import wraps
from flask import request, Response, redirect, Flask
from bokeh.util import session_id
app = Flask(__name__)
def check_auth(username, password):
return username == 'valid_user' and password == 'valid_password'
def authenticate():
"""Sends a 401 response that enables basic auth"""
return Response(
'Could not verify your access level for that URL.\n'
'You have to login with proper credentials', 401,
{'WWW-Authenticate': 'Basic realm="Login Required"'})
def requires_auth(f):
@wraps(f)
def decorated(*args, **kwargs):
auth = request.authorization
if not auth or not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
return decorated
@app.route('/')
@requires_auth
def redirect_to_bokeh():
s_id = session_id.generate_session_id()
return redirect("http://<bokeh-server-addr>:<port>/?bokeh-session-id={}".format(s_id), code=302)
if __name__ == "__main__":
app.run()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句