到目前为止,已成功使用 Python 中的 Microsoft Graph 获取现有的自定义用户流属性
import msal
# Replace with your Azure AD B2C configuration
tenant_id = 'tenantID'
client_id = 'appID'
client_secret = 'secret'
authority = f'https://login.microsoftonline.com/{tenant_id}'
# Create a confidential client application
app = msal.ConfidentialClientApplication(
client_id=client_id,
client_credential=client_secret,
authority=authority
)
# Acquire a token
result = app.acquire_token_for_client(scopes=['https://graph.microsoft.com/.default'])
access_token = result['access_token']
# Make a request to retrieve custom user attributes
import requests
graph_url = f"https://graph.microsoft.com/v1.0/identity/userFlowAttributes?$filter=userFlowAttributeType eq 'custom'"
response = requests.get(graph_url, headers={'Authorization': f'Bearer {access_token}'})
if response.status_code == 200:
result = response.json()
print(result)
else:
print("Error:", response.status_code, response.text)
如何使用 Python 中的 Microsoft graph 自动创建自定义用户流属性(例如年龄),无需 Portal
int
类型
要通过 Microsoft Graph API 创建新的用户属性,您应该发送包含以下标头的
POST /identity/userFlowAttributes
请求:
身体:
{
"displayName": "FaveNumber",
"description": "Your favourite maths number",
"dataType": "int",
}
注意,虽然这将创建用户属性,但它不会自动更新您的用户流以收集/返回属性。