Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion duo_client/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ def get_users_by_ids(self, user_ids):
def add_user(self, username, realname=None, status=None,
notes=None, email=None, firstname=None, lastname=None,
alias1=None, alias2=None, alias3=None, alias4=None,
aliases=None):
aliases=None, custom_attribute_map=None):
"""
Adds a user.

Expand All @@ -856,6 +856,9 @@ def add_user(self, username, realname=None, status=None,
lastname - User's surname for ID Proofing (optional)
alias1..alias4 - Aliases for the user's primary username (optional)
aliases - Aliases for the user's primary username (optional)
custom_attribute_map - Map of custom attributes (optional). When provided this will be of type Dict[str|str]. e.g.
{"attribute_name":"attribute_value"}
Note: the custom attribute names have to be created prior to adding users

Returns newly created user object.

Expand Down Expand Up @@ -886,6 +889,10 @@ def add_user(self, username, realname=None, status=None,
params['alias4'] = alias4
if aliases is not None:
params['aliases'] = aliases
if custom_attribute_map is not None:
for key in custom_attribute_map:
params[f'custom_attributes.{key}'] = custom_attribute_map[key]

response = self.json_api_call('POST',
'/admin/v1/users',
params)
Expand Down
3 changes: 3 additions & 0 deletions examples/Admin/create_user_and_phone.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python
import pprint
import sys
import json

import duo_client

Expand All @@ -20,6 +21,7 @@ def get_next_arg(prompt):

USERNAME = get_next_arg('user login name: ')
REALNAME = get_next_arg('user full name: ')
CUSTOM_ATTRIBUTE_MAP_STR = get_next_arg('custom attribute map (optional): ')

# Refer to http://www.duosecurity.com/docs/adminapi for more
# information about phone types and platforms.
Expand All @@ -31,6 +33,7 @@ def get_next_arg(prompt):
user = admin_api.add_user(
username=USERNAME,
realname=REALNAME,
custom_attribute_map=json.loads(CUSTOM_ATTRIBUTE_MAP_STR) if CUSTOM_ATTRIBUTE_MAP_STR else None ,
)
print('Created user:')
pprint.pprint(user)
Expand Down