docker - 使用 nginx 和 docker 部署时,Azure 验证的 Flask 应用程序中的重定向 URI 不正确
问题描述
我有一个基于以下说明构建的烧瓶应用程序,它允许我对基于 Azure AD 的用户进行身份验证。 https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-v2-python-webapp
该应用程序在测试时运行良好localhost:5000
。现在我想使用 docker 和 nginx 反向代理将它部署到生产服务器。我创建了一个 docker 容器,以便将 docker 端口映射到 localhost 上的端口 6000。然后我proxy_pass
在 nginx 配置中添加了一个将流量传递给 docker 容器。
nginx.conf
location /app/authenticated-app/ {
proxy_pass http://localhost:6000/;
proxy_redirect default;
}
使用此配置,我可以通过以下方式转到登录页面,https://server/app/authenticated-app
但是,当我单击登录时,转到 azure 的请求的查询参数redirect_uri
设置为http://localhost:6000/getToken
. 因此,一旦我完成登录,应用程序就会被重定向到该 URL。有谁知道如何解决这个问题并将其重定向到正确的网址。我已经在 azure 门户https://server/app/authenticated-app/getToken
下添加了。redirect_uri
解决方案
我有一个类似的问题,nginx 和我的烧瓶应用程序都在同一堆栈的 docker 容器中运行并使用自签名 SSL 证书。
我的 nginx 重定向请求如下:
proxy_pass http://$CONTAINER_NAME:$PORT;
并且 msal 应用程序在构建它时使用该 URLredirect_uri
def _build_auth_code_flow(authority=None, scopes=None):
return _build_msal_app(authority=authority).initiate_auth_code_flow(
scopes or [],
redirect_uri=url_for("auth.authorized", _external=True))
我通过在我的文件中硬编码我想要的返回 URL(与我在 azure 应用程序注册中配置的相同)config.py
并将其用于redirect_uri
:
def _build_auth_code_flow(authority=None, scopes=None):
return _build_msal_app(authority=authority).initiate_auth_code_flow(
scopes or [],
redirect_uri=current_app.config['HARDCODED_REDIRECT_URL_MICROSOFT'])
在我的情况下,那url
将是https://localhost/auth/redirect/
. 我还需要配置我的 nginx 以将所有请求从 http 重定向到 https:
events {}
http {
server {
listen 80;
server_name localhost;
return 301 https://localhost$request_uri;
}
...
推荐阅读
- java - 如何将 OffsetDateTime 存储到 PostgreSQL“带时区的时间戳”列
- powershell - 如何压缩太长的文件?
- html - 图像顶部的 Bootstrap 4 浅色叠加以使文本突出/看得更清楚
- vba - 将代码模块从加载项导出到普通模板
- r - 如何在具有多个列表的数据集中准确地省略(负子集)项目?
- c - 怎么处理
- r - 使用带有矩阵的 For 循环优化 R 代码
- bash - Linux 目录权限
- xcode - Cmake 在 Mac OS 10.13 和 Xcode 9.2 上失败(文件是为不受支持的文件格式构建的)
- r - R:将文本值的向量保存到 .txt 文件中(向量的每个元素到单独的 .txt 文件中)