permit.api.users.create()
Create a new user with specified user information.
Parameters
userData
- An object that contains the information about the user. The payload is defined below.
Payload
key
- A unique id by which Permit will identify the user for permission checks.
You will later pass this ID to the permit.check()
API. You can use anything for this ID; the user email - a UUID or anything else as long as it's unique on your end. The user key must be url-friendly (slugified).
email
- optional - The email of the user. If synced, will be unique inside the environment.
first_name
- optional - First name of the user.
last_name
- optional - Last name of the user.
attributes
- optional - Arbitraty user attributes that will be used to enforce attribute-based access control policies.
role_assignments
- optional - List of roles to assign to the user in the environment.
Implementation
import io.permit.sdk.openapi.models.UserCreate;
import io.permit.sdk.openapi.models.UserRead;
// optional attributes for attribute-based access control
HashMap<String, Object> userAttributes = new HashMap<>();
userAttributes.put("age", Integer.valueOf(50));
userAttributes.put("fav_color", "red");
UserRead user = permit.api.users.create(
(new UserCreate("auth0|elon"))
.withEmail("elonmusk@tesla.com")
.withFirstName("Elon")
.withLastName("Musk")
.withAttributes(userAttributes)
);
Implementation(with roles assignment)
import io.permit.sdk.openapi.models.UserCreate;
import io.permit.sdk.openapi.models.UserRead;
// optional attributes for attribute-based access control
HashMap<String, Object> userAttributes = new HashMap<>();
userAttributes.put("age", Integer.valueOf(50));
userAttributes.put("fav_color", "red");
final List<UserRoleCreate> roleAssignments = Arrays.asList(
new UserRoleCreate("editor", "default"),
new UserRoleCreate("moderator", "default"),
new UserRoleCreate("editor", "default", "myResourceType:myResourceInstance")
);
UserRead user = permit.api.users.create(
(new UserCreate("auth0|elon"))
.withEmail("elonmusk@tesla.com")
.withFirstName("Elon")
.withLastName("Musk")
.withAttributes(userAttributes)
.withRoleAssignments(roleAssignments);
);