首页 > 解决方案 > 如何在 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 中,因此只需要登录一次

标签: pythondjangoauthenticationazure-ad-graph-api

解决方案


我想这已经在这里回答了

也试试这个 Django 的 ADFS 身份验证

甚至您可以尝试使用 python 中的库

Django Microsoft 身份验证后端


推荐阅读