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:
- PHP
// Tenant user association
// Last name: the 'lastname' entered on the page
// First name: the 'firstname' entered on the page
$create_tenant_user_param = new CreateTenantUserParam();
$create_tenant_user_param->setEmail($request['userinfo']['email']);
$create_tenant_user_param->setAttributes([
'memo' => $validated['memo'],
]);
$auth_api_client->createTenantUser($tenant->getId(), $create_tenant_user_param, $auth_api_client::FETCH_RESPONSE);
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:
- PHP
// Role setting
$create_tenant_user_roles_param = new CreateTenantUserRolesParam();
$create_tenant_user_roles_param->setRoleNames(['admin']);
$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".