python - 如何在 azure ad 中实现单点登录 django auth?
问题描述
我有一个基于 django 的 Web 应用程序,客户要求我们将登录与 Azure AD 集成,遵循我设法与以下流程集成的文档。在 django 中,用户只输入电子邮件,我识别用户和他的公司并将他重定向到微软广告登录屏幕,登录后,重定向 uri 被激活,在我看来,我做了一些验证并在我的系统上对用户进行身份验证。问题是,每次客户要登录时,他都需要在 azure 中输入他的凭据,是否可以使用 microsoft user_id 或用户第一次登录登录时获取的令牌?或者其他更快的登录方式?
这是我的回调视图,在 redirect_uri 中调用:
def callback(request):
user_id = request.session.pop('user_id', '')
user_internal = User.objects.filter(id=user_id).first()
company_azure = CompanyAzureAd.objects.filter(company=user_internal.employee.firm).first()
# Get the state saved in session
expected_state = request.session.pop('auth_state', '')
# Make the token request
url = request.build_absolute_uri(request.get_full_path())
token = get_token_from_code(url, expected_state, company_azure)
# Get the user's profile
user = get_user(token) #in this moment i have user microsoft profile, with token and id
# Save token and user
store_token(request, token)
store_user(request, user)
...
如果可以登录,我可以将令牌或用户 ID 存储在我的数据库中的 microsoft 中,因此只需要登录一次
解决方案
推荐阅读
- tensorflow - Tensorflow - ValueError:从拆分数组创建数据集时无法将 NumPy 数组转换为张量
- python - Python Web-scraping - 嵌套标签
- c - 创建结构c时结构中的问题
- python - 在另一个方法中模拟方法中的输入
- python-3.x - 为什么我无法访问网站的完整响应代码?
- c - Flex:REJECT 一次拒绝一个角色?
- java - 如何从 c++ 和 swig 重定向 python 和 java 打印
- javascript - For循环不会迭代
- python - 如何编写一个在给定时间和日期执行的函数。discord.py(后台任务)
- tailwind-css - 如何在顺风弯曲中对齐按钮?