NOTE: Trivore ID Documentation has moved to https://trivoreid.com
The content on this site IS OUT OF DATE!
This space has been archived!
Please go ahead to the new site!
User Service (python)
Wrapper for the '/user' API. Contains most of the user operations except profile functions, as profile service is disabled when Management API is used.
NB! If user is assigned to a group name (memberOf) that doesn't exist, then the new group will be created.
List of all options:
Get all users
Get one/create/modify/delete user
Verify email/phone with code or link (primary ones)
Get/update/delete custom user fields (dictionary with any keys/values)
Get/update user enterprise
Get password requirements (min and max password length)
Get user's legal info
Migrate user to other namespace
Change password
Get/update custom permission
Get/update builtin and custom roles
Get/report strong identification
Get/update student info
User management
from trivoreid.utils.criteria import Filter
from trivoreid.models.email import EmailAddress
from trivoreid.models.user import (User,
Names,
Mobile,
Address)
# get list of users
users = api.user_service.get_all(Filter(Filter.EQUAL, 'nsCode', 'examplecode')).resources
# create new user object
user_to_create = User({
'nsCode' : 'testsdk',
'emails' : ['example1@trivore.com'],
'memberOf' : ['gr003', 'gr004'] # if groups with user's nsCode and member
# names don't exist, they will be created
})
user_names = Names({
'givenName' : 'First Name',
'middleName' : 'Middle Name',
'familyName' : 'Last Name'})
user_addresses = [Address({
'addressName' : 'address',
'name' : 'home',
'country' : 'FI',
'locality' : 'fi',
'postalCode' : '20750',
'region' : 'Region',
'streetAddress' : 'Street Address 5C'})]
email1 = EmailAddress({'address' : 'example1@trivore.com'})
email2 = EmailAddress({'address' : 'example2@trivore.com',
'tags' : ['tag1', 'tag2'], 'name' : 'work'})
user_emails = [email1, email2]
mobile1 = Mobile({'number' : '+358402592078'})
mobile2 = Mobile({'number' : '+358402592077',
'tags' : ['tag1', 'tag2'], 'name' : 'work'})
user_mobiles = [mobile1, mobile2]
user_to_create.name = user_names
user_to_create.addresses = user_addresses
user_to_create.emails = user_emails
user_to_create.mobiles = user_mobiles
# user service returns new user object and a randomly generated password with
# the defined length (15 by default).
new_user = api.user_service.create(user_to_create, password_length=30)[0]
user = api.user_service.get(new_user.user_fields['id'])
print('Password : {}'.format(new_user.serialize()['password']))
print('\n User fields \n {}'.format(user.serialize()))
# deleting user account
api.user_service.delete(user.user_fields['id'])
# creating multiple users
user_list = []
for _ in range(5):
user_list.append(User({'nsCode' : 'testsdk'}))
# result is the list of created users
result = api.user_service.create(user_list)
Email / Mobile verification
userId = new_user.id
# send verification link to the user e-mail address
api.user_service.verify_email(userId, expiration_days=1)
# send verification code to the mobile
api.user_service.verify_sms_code(userId)
# verify mobile
api.user_service.verify_sms_code_check(userId, '1234')
#send verification link to the user mobile number
api.user_service.verify_sms_link(userId)
Custom user fields
Enterprise and password requirements
Email / Mobile tags
User's Consents
Migrate namespace
Warning: Original user will be deleted and another will be created in the target namespace. Not all information will be migrated!