有没有办法使用python
创建带凭据的okta用户创建没有恢复问题的用户&回答。新用户将在激活后立即使用指定的密码登录。在开发自定义用户注册体验时,此流程很常见。
curl -v -X POST \
-H "Accept: application/json" \
-H "Content-Type: application/json" \
-H "Authorization: SSWS ${api_token}" \
-d '{
"profile": {
"firstName": "Isaac",
"lastName": "Brock",
"email": "isaac.brock@example.com",
"login": "isaac.brock@example.com",
"mobilePhone": "555-415-1337"
},
"credentials": {
"password" : { "value": "tlpWENT2m" }
}
}' "https://${org}.okta.com/api/v1/users?activate=false"
这是使用Curl
答案 0 :(得分:3)
在Python中使用requests library:
import requests
url = '{{org}}.okta.com/api/v1/users'
headers = {
'accept': 'application/json',
'authorization' : 'SSWS {{api_token}}',
'content-type': 'application/json'
}
body = {
'profile': {
'firstName': 'Isaac',
'lastName': 'Brock',
'email': 'isaac@{{email_suffix}}',
'login': 'isaac@{{email_suffix}}'
},
'credentials': {
'password' : { 'value': '{{password}}' }
}
}
r = requests.post(url, headers=headers, json=body)
# r.json
使用Okta Python SDK,您需要先创建client
,然后调用create_user()
方法。
from okta import UsersClient
from okta.models.user import User
usersClient = UsersClient("https://{{org}}.okta.com", "{{api_token}}")
user = User(login='isaac@{{email_suffix}}',
email='isaac@{{email_suffix}}',
firstName='Isacc',
lastName='Brock')
user = usersClient.create_user(user, activate=False)