gpt4 book ai didi

python - 如何使用 Django 从 Azure AD 检索员工 ID?

转载 作者:行者123 更新时间:2023-12-03 02:21:34 25 4
gpt4 key购买 nike

Image of employee id

我正在尝试使用 Django 检索员工 ID,如上所示。该平台源自 Azure Active Directory。 调用员工 ID 的参数或方式有哪些?

最佳答案

您可以使用Microsoft Graph API调用用户并获取员工ID。为了从 Django 应用程序调用它,您必须使用 ADAL 库。

代码:

import adal,requests

url = 'https://login.microsoftonline.com/yourtenant.onmicrosoft.com/oauth2/v2.0/token'
data = {
'grant_type': 'client_credentials',
'client_id': "your_client_id",
'scope': 'https://graph.microsoft.com/.default',
'client_secret': "your_client_secret"
}
r = requests.post(url, data=data)
token = r.json().get('access_token')

url = ’https://graph.microsoft.com/v1.0//users?&$select=displayName,jobTitle,employeeID’
headers = {
'Content-Type' : 'application\json',
'Authorization': 'Bearer {}'.format(token)
‘ConsistencyLevel’ : ’eventual’
}
r = requests.get(url, headers=headers)
result = r.json()
print(result)

我已经使用 Graph explorer 测试了该 URL 及其工作原理。

https://graph.microsoft.com/v1.0//users?&$select=displayName,jobTitle,employeeID

上述网址将提供您的 AAD 中存在的所有用户,并且仅选择显示名称、职务和员工 ID 并显示它。

enter image description here

注意:在 Azure AD 中注册应用程序并在 API 权限中注册后,请确保应用程序具有 User.Readall 权限集以获取详细信息。

引用:

django - How to access the Azure AD Groups and user details using python? - Stack Overflow

AzureAD/azure-activedirectory-library-for-python: ADAL for Python (github.com)

Querying Microsoft Graph API with Python | by Ephraim Mwai | Towards Data Science

关于python - 如何使用 Django 从 Azure AD 检索员工 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68646165/

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