这可能是由于客户端 ID 无法在创建时提供或API 使用的客户端 ID 不正确导致的。以下是通过Auth0 API创建用户的示例代码,其中客户端 ID 和客户机密作为参数提供:
import requests
import base64
client_id = 'your_client_id'
client_secret = 'your_client_secret'
# Set up the API request
auth_url = 'https://your_domain.auth0.com/oauth/token'
api_url = 'https://your_domain.auth0.com/api/v2/users'
headers = {'content-type': 'application/json'}
payload = {
'client_id':client_id,
'client_secret':client_secret,
'grant_type':'client_credentials'
}
# Get the access token
auth_response = requests.post(auth_url,json=payload,headers=headers)
access_token = auth_response.json().get('access_token')
# Set up the user creation request
user_payload = {
'email': 'user@example.com',
'password': 'password123'
}
user_headers = {
'authorization': 'Bearer {}'.format(access_token),
'content-type': 'application/json'
}
# Create the user
user_response = requests.post(api_url,json=user_payload,headers=user_headers)
user = user_response.json()
print(user)
请确保替换“your_client_id”和“your_client_secret”为您的客户端 ID 和客户端密钥。