自动创建自定义用户流属性 Python Azure B2C

问题描述 投票:0回答:1

到目前为止,已成功使用 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
类型

python azure-ad-msal aad-b2c azure-app-registration msal
1个回答
0
投票

要通过 Microsoft Graph API 创建新的用户属性,您应该发送包含以下标头的

POST /identity/userFlowAttributes
请求:

  • 授权:不记名{token}
  • 内容类型:application/json

身体:

{
  "displayName": "FaveNumber",
  "description": "Your favourite maths number",
  "dataType": "int",
}

请参阅:Microsoft Learn 文档

注意,虽然这将创建用户属性,但它不会自动更新您的用户流以收集/返回属性。

© www.soinside.com 2019 - 2024. All rights reserved.