使用Azure AD跳flask-dance失败



我试图实现在flask上运行的一个示例dash应用程序的OAuth认证。应用程序在Azure AD中注册,但当尝试与flask-dance库进行身份验证时,我得到这个错误:

错误AADSTS70001 -在目录

中找不到标识符为None的应用程序
from dash import Dash, html
from werkzeug.middleware.proxy_fix import ProxyFix
from flask import Flask, redirect, url_for
from flask_dance.contrib.azure import azure, make_azure_blueprint
import os

CLIENT_ID = os.environ.get("CLIENT_ID")
CLIENT_SECRET = os.environ.get("CLIENT_SECRET")

def login_required(func):
"""Require a login for the given view function."""
def check_authorization(*args, **kwargs):
if not azure.authorized or azure.token.get("expires_in") < 0:
return redirect(url_for("azure.login"))
else:
return func(*args, **kwargs)
return check_authorization
blueprint = make_azure_blueprint(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
tenant="MyTenant", # Hidden for this example
scope=["user.read"],
)

app = Flask(__name__)
app.config["SECRET_KEY"] = "secretkey123"
app.register_blueprint(blueprint, url_prefix="/login")
# dash_app = create_app(server=app)
dash_app = Dash(__name__, server=app)
# use this in your production environment since you will otherwise run into problems
# https://flask-dance.readthedocs.io/en/v0.9.0/proxies.html#proxies-and-https
app.wsgi_app = ProxyFix(app.wsgi_app, x_proto=1, x_host=1)
for view_func in app.view_functions:
if not view_func.startswith("azure"):
app.view_functions[view_func] = login_required(app.view_functions[view_func])
dash_app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
html.Div(children="You are logged in!")
])
if __name__ == '__main__':
dash_app.run_server(debug=True, port=5010, host="localhost")

问题出在范围。这是不必要的,当它被删除,其余的工作正常

相关内容

  • 没有找到相关文章

最新更新