Skip to content

Users

An application often needs to create users on the platform: a customer’s staff, a new employee, an administrator. The Java SDK has two ways to do it, for two different cases.

You want to Use
Create any user and choose who sends the “set your password” mail client.principals().createUser(...)
Manage the users and invitations of one application, from its own admin pages client.applicationUsers()

The concepts are in principals and the how-to in users and invitations.

principals().createUser(CreateUserRequest) returns a PrincipalResponse. email and name are required. Two flags decide who sends the invitation. Prefer pattern 1 when you want the user to land back inside your own application.

Create the user with sendInvitation(false) and send your own email that links to your application. The platform detects the passwordless account at the hosted login, handles password creation itself and then returns the user to your stored OAuth redirect.

PrincipalResponse user = client.principals().createUser(new CreateUserRequest()
.email("new.user@example.com")
.name("New User")
.sendInvitation(false));
// Send your own "welcome" email now, linking to your app.

sendInvitation(false) suppresses both the invitation and the “account created” welcome email; the platform sends nothing.

Create the user with returnInviteLink(true) and read inviteLink from the response to embed in your own email. The user sets a password on the platform and lands where inviteRedirectUri points, or the platform console if you gave none.

PrincipalResponse user = client.principals().createUser(new CreateUserRequest()
.email("new.user@example.com")
.name("New User")
.inviteRedirectUri("https://app.example.com/welcome")
.returnInviteLink(true));
String inviteLink = user.getInviteLink();
// Embed inviteLink in your own email. Never log it or store it in plaintext.
  • returnInviteLink(true) always suppresses the platform’s own invitation email, even when sendInvitation is left at its default. The token can only be minted once per delivery, so asking for the link back means you are taking over delivery.
  • The link is a live 72-hour bearer credential, exactly like a password.
  • It applies to a passwordless internal user only. A federated user has no password step, and a user created with a password has nothing to set.
  • inviteRedirectUri is where the invitee goes after setting a password (and enrolling a second factor, where their domain requires it). It is not an OAuth redirect URI. Any absolute http(s) URL is accepted; a malformed value rejects the request before the user is created (INVITE_REDIRECT_URI_INVALID).
Member Meaning
password Create the user with a password. The full password policy applies (length bounds, the common-password blocklist, not derived from the user’s email or name). enforcePasswordComplexity(false) hands the policy to your application: the platform then checks only a minimal floor.
scope ANCHOR, PARTNER or CLIENT. Defaults to CLIENT; the email domain never raises it. ANCHOR is honoured only if the domain is a registered anchor domain, PARTNER only with a matching partner mapping.
clientId The home client: a clt_ id or the client’s identifier slug. An unknown reference is rejected rather than ignored.

list(Filters), get(id), listByEmail(email), update, activate, deactivate, resetPassword, getRoles, addRole, removeRole, setRoles, getClientAccessGrants, grantClientAccess, revokeClientAccess, sync(...) and syncUsers(list). syncUsers is the application-less user sync, keyed by email; the application-scoped form is part of declarations.

An application’s own users and invitations

Section titled “An application’s own users and invitations”

An application’s admin pages call the platform as the application’s own service account, after your application has checked that the signed-in person may administer users. The account is confined to its application:

  • events and dispatch jobs: only those whose code starts with the application’s code;
  • users: only the ones the application owns, meaning CLIENT users at clients the application is enabled for who hold one of its roles.

Another application’s data answers 403 (for a code) or 404 (for an id). A credential bound to no application is refused with 403.

var users = client.applicationUsers();
var page = users.list("orders", ApplicationUsersResource.Filters.page(0, 50));
var one = users.get("orders", userId);
users.invite("orders", new InviteApplicationUserRequest()
.email("ann@acme.test").name("Ann").clientId("acme").roles(List.of("orders:clerk")));
var pending = users.invitations("orders", "PENDING", 0, 50); // never carries a link
users.resend("orders", userId, null); // a fresh link; the earlier one dies
users.revoke("orders", userId); // deletes the link, deactivates the user
  • invite creates a user at one of the application’s enabled clients with at least one of its roles. email, name, clientId and roles are required. sendInvitation (default true) has the platform email the invitation; returnInviteLink gives back the live link instead and suppresses the email. Treat the link like a password.
  • invitations(app, status, page, pageSize) lists users who have not set a password. status is PENDING (a live link exists), EXPIRED (resend it) or null for both. A listing never carries a link.
  • resend mints a fresh link, so the earlier one stops working, and emails it. Pass a ResendInvitationRequest with returnInviteLink to receive it instead.
  • revoke deletes the link and deactivates the user, who has never signed in. The record stays; reactivating it is a console action.

Reading the application’s own events and jobs

Section titled “Reading the application’s own events and jobs”

The same credential also reads the application’s activity, for an admin page or a support tool:

var events = client.events().list(EventsResource.Filters.page(50, 0)); // newest first
var jobs = client.dispatchJobs().list(DispatchJobsResource.Filters.page(50, 0));
var attempts = client.dispatchJobs().attempts(jobs.getFirst().getId());

events().get(id), dispatchJobs().get(id) and dispatchJobs().byEvent(eventId) are also available.

The built-in platform:application-service role must carry event:view, dispatch-job:view, user:view, user:create, invitation:view and invitation:manage. Mint a new token after the role gains a permission, because permissions ride in the token. See permissions.