Skip to main content

Assigning Users to Tenants and Setting Roles

After a tenant has been created, you can then associate the self-signed up user with the tenant.

Please append the following to the tenant creation source code:

    // Retrieve user attribute information
$userAttributesResponse = $authClient->getUserAttributes();
$userAttributes = $userAttributesResponse->getUserAttributes();
foreach ($userAttributes as $attribute) {
$attributeName = $attribute->getAttributeName();
$attributeType = $attribute->getAttributeType();

// Replace if a number type is defined in the user attribute information
if (isset($userAttributeValues[$attributeName]) && $attributeType === 'number') {
$userAttributeValues[$attributeName] = (int) $userAttributeValues[$attributeName];
}
}

// Create parameters for tenant user registration
$createTenantUserParam = new CreateTenantUserParam();
$createTenantUserParam
->setEmail($email)
->setAttributes($userAttributeValues);

// Add a SaaS user to the tenant users
$tenantUser = $authClient->createTenantUser($tenantId, $createTenantUserParam);

Please use the CreateTenantUserParam object.

setAttributes sets the attribute information of the tenant defined in Defining Additional Attributes for a Tenant.

Next, set the role.

Please append the following code:

    // Create parameters for role configuration
$create_tenant_user_roles_param = new CreateTenantUserRolesParam();
$create_tenant_user_roles_param->setRoleNames(['admin']);

// Assign a role to the created tenant user
$auth_api_client->createTenantUserRoles($tenant->getId(), $request['userinfo']['id'], getenv('DEFAULT_SAASUSER_ENV'), $create_tenant_user_roles_param);

Please use the CreateTenantUserRolesParam object.

setRoleNames allows you to specify multiple roles.

The values that can be specified are the "Role Name" that you created in Role Definition.

You can check whether the tenant user was registered via API in "SaaS Operation Console > User Management".

user