Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 简单用户名&;bokeh服务器的密码保护_Python_Azure_Authentication_Password Protection_Bokeh - Fatal编程技术网

Python 简单用户名&;bokeh服务器的密码保护

Python 简单用户名&;bokeh服务器的密码保护,python,azure,authentication,password-protection,bokeh,Python,Azure,Authentication,Password Protection,Bokeh,我有一个简单的bokeh服务器应用程序,我想在基于Linux的Azure节点上公开它。服务器已经启动并正在运行 我的问题是:如何通过用户名和密码保护内容?我不需要用户的身份验证 到目前为止我的想法(没有尝试过,可能行不通) 创建带有文本字段的额外bokeh服务器页面 在按钮的回调上,如果密码合适,则添加测试。如果是,则重定向到原始服务器页面。否则,请通知用户错误的凭据 您可以尝试禁用bokeh服务器生成会话id,并仅在用户身份验证后通过外部应用程序生成会话id: (基于bokeh文件的格式) 使

我有一个简单的bokeh服务器应用程序,我想在基于Linux的Azure节点上公开它。服务器已经启动并正在运行

我的问题是:如何通过用户名和密码保护内容?我不需要用户的身份验证

到目前为止我的想法(没有尝试过,可能行不通)

  • 创建带有文本字段的额外bokeh服务器页面
  • 在按钮的回调上,如果密码合适,则添加测试。如果是,则重定向到原始服务器页面。否则,请通知用户错误的凭据

  • 您可以尝试禁用bokeh服务器生成会话id,并仅在用户身份验证后通过外部应用程序生成会话id:
    (基于bokeh文件的格式)

  • 使用
    bokeh secret
    命令生成密钥:
  • 设置另一个环境变量:
  • 在此模式下,用户应提供有效(签名)会话id以访问bokeh服务器

  • 运行简单的外部流程,询问用户的登录名和密码,并为他们生成id。 以下是基于烧瓶文档的示例:
  • 
    从functools导入包装
    来自烧瓶导入请求、响应、重定向、烧瓶
    从bokeh.util导入会话\u id
    app=烧瓶(名称)
    def check_auth(用户名、密码):
    返回用户名==“有效用户”和密码==“有效密码”
    def authenticate():
    “”“发送启用基本身份验证的401响应”“”
    返回响应(
    '无法验证您对该URL的访问级别。\n'
    “您必须使用正确的凭据登录”,401,
    {'WWW-Authenticate':'Basic realm=“Login Required”})
    def需要_auth(f):
    @包装(f)
    def装饰(*args,**kwargs):
    auth=request.authorization
    如果未验证或未验证,请检查\u auth(auth.username,auth.password):
    返回身份验证()
    返回f(*args,**kwargs)
    回报
    @应用程序路径(“/”)
    @需要授权
    def将_重定向到_bokeh():
    s_id=会话_id.generate_session_id()
    返回重定向(“http://://?bokeh会话id={}”。格式(s_id),代码=302)
    如果名称=“\uuuuu main\uuuuuuuu”:
    app.run()
    
  • 现在要访问bokeh服务器,用户应该转到Flask应用程序并指定登录名和密码

  • 根据您在没有用户认证的情况下的安全需求,我不理解您在没有用户认证的情况下的安全场景,这很奇怪,请发布更多详细信息。我建议参考文档,了解Azure和AzureAD上的保护机制。 $ bokeh secret oIWDL7DVYCaBJG9eYQ2Wvf2f2uhOAIM8xNS8Kds3eizV $ export BOKEH_SECRET_KEY=oIWDL7DVYCaBJG9eYQ2Wvf2f2uhOAIM8xNS8Kds3eizV $ export BOKEH_SIGN_SESSIONS=True $ bokeh serve myApp --session-ids external-signed
    
    
        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()