python - 为什么 Azure Active Directory OAuth 适合我而不适合其他人?

标签 python flask oauth-2.0 azure-active-directory

我正在开发一个 Python/Flask 应用程序,我想使用 OAuth 进行登录。我的雇主使用 Azure Active Directory,因此我尝试将其作为 OAuth 提供商进行集成。

我不是 Azure 租户管理员。

我创建了应用注册并按照 Microsoft 文档设置了代码,但我是唯一可以成功登录该应用的人。

我正在构建这样的授权 URL(我的代码中有正确的租户名称、客户端 ID 和重定向 URI):

import urllib.parse
import uuid

authorization_endpoint = 'https://login.microsoft.com/my-tenant.onmicrosoft.com/oauth2/authorize'
query = {
    'client_id': 'my-client-id',
    'nonce': uuid.uuid4(),
    'redirect_uri': 'https://my-app.example.com/authorize',
    'response_mode': 'form_post',
    'response_type': 'id_token',
    'scope': 'openid',
    'state': uuid.uuid4()
}
authorization_url = f'{authorization_endpoint}?{urllib.parse.urlencode(query)}'

当我亲自测试登录应用程序时,一切正常。但是,当其他人尝试时,他们会访问授权 URL,使用其凭据登录,然后得到包含以下错误的页面:

AADSTS165000: Invalid Request: The request tokens do not match the user context. Do not copy the user context values (cookies; form fields; headers) between different requests or user sessions; always maintain the ALL of the supplied values across a complete single user flow. Failure Reasons:[Token values do not match;]

为什么它对我有用而对其他人不起作用?

最佳答案

授权端点错误。它应该是 https://login.microsoftonline.com/... 而不是 https://login.microsoft.com/...

关于python - 为什么 Azure Active Directory OAuth 适合我而不适合其他人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56258855/

相关文章:

php - laravel 护照撤销和修剪事件监听器没有执行任何操作

python - matplotlib 从颜色栏中删除刻度(轴)

python - 多个 Bokeh 服务器集成到 Flask

python - Flask 函数装饰器在定义时和调用时运行?

ios - 如何识别 OAuth token 是否已过期?

go - Go 中对 Google API 的无人值守授权

python - 如何禁用 python 中的 webbrowser 消息?

java - 将 String 转换为 readUTF() 期望的格式

python - 根据列中的范围扩展 Pandas 数据框

python - Flask 应用程序无法解析子网址