単純なボケサーバーアプリケーションがあり、LinuxベースのAzureノードで公開したいと思います。サーバーは稼働しています。
私の質問は、ユーザー名とパスワードでコンテンツを保護する方法です。必ずしもユーザーの認証は必要ありません。
これまでの私のアイデア(試していません、うまくいかないかもしれません)
bokehサーバーによるセッションIDの生成を無効にして、ユーザー認証後にのみ外部アプリケーションによって生成することができます:( bokehドキュメントのこの部分に
基づく)
bokeh secret
次のコマンドで秘密鍵を生成します。$ボケ秘密 oIWDL7DVYCaBJG9eYQ2Wvf2f2uhOAIM8xNS8Kds3eizV
BOKEH_SECRET_KEY
環境変数を生成された値に設定します。$ export BOKEH_SECRET_KEY = oIWDL7DVYCaBJG9eYQ2Wvf2f2uhOAIM8xNS8Kds3eizV
$ export BOKEH_SIGN_SESSIONS = True
--session-ids external-signed
引数を指定してbokehサーバーを実行します。$ bokehはmyAppを提供します--session-idsexternal-signed
このモードでは、ユーザーはボケサーバーにアクセスするために有効な(署名された)セッションIDを提供する必要があります。
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]
コメントを追加