gpt4 book ai didi

http - Microsoft AD 应用程序验证失败 : "microsoft-identity-association.json has a content length that is not set or otherwise invalid"

转载 作者:行者123 更新时间:2023-12-01 21:54:53 25 4
gpt4 key购买 nike

我正在努力使用 Azure Active Directory 验证我们的应用程序,以使用他们的 SSO。

为了验证我们的域,他们要求在以下地址提供一个 JSON 文件:{publisher_domain}/.well-known/microsoft-identity-association.json

在我们的 Flask 应用程序中,我使用以下路径提供文件:

@app.route('/.well-known/microsoft-identity-association.json')
def microsoft_identity_association():
file = '.well-known/microsoft-identity-association.json'

return send_file(file, mimetype='application/json')

我还尝试将 JSON 加载到字典中并返回让 Flask 呈现响应的字典:

@app.route('/.well-known/microsoft-identity-association.json')
def microsoft_identity_association():
file = '.well-known/microsoft-identity-association.json'
with open(file, encoding="utf-8") as file:
result = ujson.load(file)
response = flask.Response(result, mimetype='application/json')
response.headers.add('content-length' , str(result.__len__()))

return send_file(file, mimetype='application/json')

但每次,我都得到相同的结果:

在对 GET 请求的响应中,content-length header 存在于我的本地环境中,但当我的应用程序部署在 Google App Engine Flex 上时消失了。我检查了他们的文档 ( https://cloud.google.com/appengine/docs/flexible/python/reference/request-headers ) 并联系了他们,但没有真正成功。
他们说“这似乎按预期工作。HTTP/2 不需要“内容长度”,因此它被剥离了。”

这个 Microsoft 应用程序验证程序似乎是新的(2019 年 5 月),因此很难找到类似的问题。

这里有没有人面临同样的情况并希望找到解决方案?

最佳答案

经过更多研究并在不同的技术支持之间花费了一些时间,我终于找到了一个解决方案来验证我们的应用程序。我会在这里解释它以防它对某人有用。

问题原因

Microsoft Azure AD 提出的验证过程是向我们服务器上的端点发出 GET 请求,并期待带有正确“content-lenght” header 的“aplication/json”响应。

但是我们的服务器使用的是 HTTP 1.1 协议(protocol)并且

For version 1.1 of the HTTP protocol, the chunked transfer mechanismis considered to be always acceptable, even if not listed in the TErequest header field, and when used with other transfer mechanisms,should always be applied last to the transferred data and never morethan one time. (Source: Wikipedia)

A sender MUST NOT send a Content-Length header field in any messagethat contains a Transfer-Encoding header field.
(Source: RFC)

验证过程似乎不符合 HTTP 1.1 协议(protocol)。

解决方案

解决方案最终非常简单:使用替代域验证程序

在 Azure AD 上,我能够使用 DN 上的 TXT 记录验证我们的域,如 Microsoft documentation 中所述

我希望这能帮助其他受困于应用域验证的人。

关于http - Microsoft AD 应用程序验证失败 : "microsoft-identity-association.json has a content length that is not set or otherwise invalid",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58454479/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com