Sign-up, OAuth & Invitations

Team Invitations

RESTHeart Ulabase

Team invitations allow users with the owner role to add people to their team.

Note
The invite endpoint reads the caller’s active team and role from the membership provider, not from the JWT: no claim is required for it, and a token issued before a switch of team acts as the team active now. Since 9.12.0 the tokens carry no team claim: a client reads its team from GET /auth/teams or the switch-team response, or the deployment lists "@team" in jwtConfigProvider.account-properties-claims to have it in every token (see The active team in the token).

The behavior differs depending on whether the invited user already has an account.

flowchart TD
  A[POST /auth/invite\nrequires owner role] --> B{User exists?}
  B -- No --> C[Check pending invitation\nin auth_invitations]
  C -- Pending exists --> L2[409 Conflict]
  C -- None --> D[Create user roles: $unauthenticated\nCreate auth_invitations doc isNewUser=true]
  D --> E[Email: /auth/activate\n?email=…&token=…]
  E --> F1[PATCH /auth/activate\nemail + token + password]
  E --> F2[OAuth authorize\n?pendingInviteToken=…]
  F1 --> G[Set password\nMembershipProvider.addMember\nroles → user\nDelete auth_invitations\nAuto-login JWT cookie]
  F2 --> G2[addMember from invite\nactivateViaOAuth\nDelete auth_invitations\nJWT cookie]

  B -- Yes, not in team --> H[Create auth_invitations doc\nisNewUser=false TTL 7 days]
  H --> I[Email: /invitations/accept\n?email=…&token=…]
  I --> J1[POST /auth/accept-invite\ntoken — auth required]
  I --> J2[OAuth authorize\n?pendingInviteToken=…]
  J1 --> K[MembershipProvider.addMember\nsetActiveMembership\nDelete auth_invitations\n200 OK]
  J2 --> K

  B -- Yes, already member --> L[409 Conflict]

Invite a user

POST /auth/invite: requires role owner.

Request

POST /auth/invite
Authorization: Bearer <token>
Content-Type: application/json

{
  "email":  "bob@example.com",
  "role":   "member",
  "locale": "it"
}

locale is optional, since 9.17.1: the language of the invitation email. For a new user it is also stored on the user document the invitation creates, so the later emails reach them in the same language. For an existing user it is used only if the user has no locale of their own, and it is never stored. An invalid locale is refused with 400. See Locale resolution.

role must be one of: the configured member-role-name (default "member") or the configured ownership-role (default "owner").

Important
The admin role is a system-level ACL role in RESTHeart and should NEVER be used as a team/membership role. Using admin as a membership role grants the user unrestricted access to the entire system.

Server-side steps

  1. Authorize the caller (must be owner of their team).

  2. Validate email format, role value and locale, when present.

  3. If the user already belongs to the caller’s team → 409 Conflict.

  4. If a pending invitation already exists for the same email+team in auth_invitations → 409 Conflict.

  5. If the user does not exist → create user with roles: ["$unauthenticated"]. Create an auth_invitations document with isNewUser: true. Send activation email with link to {frontend-url}/auth/activate?email=…​&token=…​. The membership is added only when the user activates the account.

  6. If the user exists but is NOT in this team → create an auth_invitations document with isNewUser: false. Do NOT add membership yet. Send invite email with link to {frontend-url}/invitations/accept?email=…​&token=…​.

  7. Return 201 Created.

Note

The invitation tokens of new and existing users are stored only in the auth_invitations collection, in the same database as users and acl. The user documents get no inviteToken or inviteCreatedAt field.

The auth_invitations document schema:

{
  "_id":       {"$oid": "..."},
  "email":     "user@example.com",
  "token":     "64-char hex",
  "teamId":     {"$oid": "..."},
  "role":      "member",
  "isNewUser": true,
  "createdAt": {"$date": 1234567890},
  "expiresAt": {"$date": 1234567890}
}
Important
The token activates the invited account, so nobody but the invitee must learn it. A permission that lets a role read auth_invitations should hide it with projectResponse. Since v9.17 RESTHeart also refuses, with 403, any request whose filter or sort refers to token in auth_invitations: a condition on a hidden field would reveal its value over several requests. See Security Hardening.
User type Email link

New user (no account)

{frontend-url}/auth/activate?email=…​&token=…​

Existing user

{frontend-url}/invitations/accept?email=…​&token=…​

Read invitation metadata

GET /auth/invitation?email=…​&token=…​: public.

The frontend calls this on page load to determine which UI to show and to display the team name and role.

Both parameters are required. The (email, token) pair is known only to the invitee (delivered via private email link), so this endpoint cannot be used for enumeration.

Response 200 OK

{
  "email":     "bob@example.com",
  "teamName":   "Acme Corp",
  "role":      "member",
  "isNewUser": true,
  "expiresAt": "2026-06-24T10:00:00Z"
}

Frontend behavior

  • isNewUser: true → show "Set your password" form + OAuth buttons → PATCH /auth/activate

  • isNewUser: false → show "Log in to accept" form + OAuth buttons → login then POST /auth/accept-invite

Error responses

Status Reason

400

Missing email or token parameter

404

No valid (non-expired) invitation found for that (email, token) pair

Activate an invitation (new user)

PATCH /auth/activate is public: the user has only the link with the token.

Request

PATCH /auth/activate
Content-Type: application/json

{
  "email":    "bob@example.com",
  "token":    "<token from email>",
  "password": "correct-horse-battery"
}

Server-side steps

  1. Find invitation by (email, token) in auth_invitations (not on user document).

  2. Verify isNewUser: true. Otherwise 400: this is the wrong endpoint for the invitation.

  3. Check expiry (TTL 7 days).

  4. Enforce password strength.

  5. Set password, assign roles: ["user"].

  6. MembershipProvider.addMember(userId, teamId, role) adds the user to the team and makes it the active team. teamId and role come from the invitation document.

  7. Delete invitation from auth_invitations (one-shot).

  8. Issue JWT → auto-login. The token is delivered per the optional delivery query parameter: cookie (default, sets the rh_auth cookie) or body (since 9.6.0), which returns access_token, token_type and expires_in in the response body and the Auth-Token header, without a cookie. Use body for a cross-origin SPA that sends a Bearer token.

  9. Return 200 OK.

Note
Consents are not managed by this endpoint. See Consents Management for details.

=== Error responses

Status Reason

400

Missing fields; password too weak; isNewUser=false (wrong endpoint)

401

Invalid or expired invite token

== Accept an invitation (existing user)

POST /auth/accept-invite: requires authentication.

=== Request

POST /auth/accept-invite
Authorization: Bearer <token>
Content-Type: application/json

{
  "token": "<token from email>"
}

=== Server-side steps

  1. Find invitation by token in auth_invitations.

  2. Verify isNewUser: false. Otherwise 400: this is the wrong endpoint for the invitation.

  3. Verify invitation email matches the authenticated user.

  4. MembershipProvider.addMember(userId, teamId, role) adds the user to the team.

  5. MembershipProvider.setActiveMembership(userId, teamId) makes the new team the active one.

  6. Delete invitation from auth_invitations.

  7. Return 200 OK.

=== Frontend flow

  1. User clicks link in email → /invitations/accept?email=…​&token=…​

  2. Frontend calls GET /auth/invitation?email=…​&token=…​ to get team name and role.

  3. If not logged in → shows "Log in to accept" with OAuth buttons + login form.

  4. After login → calls POST /auth/accept-invite { token }.

  5. On success → redirect to dashboard.

== Accept via OAuth

Both new and existing invited users can accept via OAuth. The pendingInviteToken is passed as a query parameter to the OAuth authorize URL.

=== OAuth URL

{api-base-url}/auth/oauth/authorize/{provider}?pendingInviteToken=...

=== New user (roles: $unauthenticated)

  1. OAuth callback detects $unauthenticated user with pendingInviteToken.

  2. Find invitation by (email, pendingInviteToken) in auth_invitations; call MembershipProvider.addMember(userId, teamId, role) to set team.

  3. Clear the placeholder password and record the provider in socialAuths (since 9.13.0).

  4. MembershipProvider.activateViaOAuth(userId, consents) assigns roles: ["user"] and stores the consents.

  5. Delete invitation from auth_invitations. JWT cookie set, redirect to frontend-app-url.

=== Existing user

  1. OAuth callback detects user is NOT $unauthenticated and pendingInviteToken is present.

  2. Find invitation by (email, pendingInviteToken) in auth_invitations.

  3. MembershipProvider.addMember(userId, teamId, role).

  4. Delete invitation. Issue JWT. Redirect to frontend-app-url.

== Re-send an invitation

POST /auth/resend-invite: requires role owner.

Request body:

{ "email": "bob@example.com", "locale": "it" }

locale is optional, since 9.17.1: the language of the email, used only if the invited user has no locale. A new user invited with a locale has that one. It is never stored.

Generates a new token (invalidating the previous one) by updating the auth_invitations document, and re-sends the invitation email. Works for both new and existing user invitations. Returns 200 OK on success. Returns 404 if no pending invitation is found for that user in the caller’s team.

== List pending invitations

GET /auth/invitations requires authentication, as owner or admin.

Returns all pending (non-expired) invitations for the caller’s active team. The response never includes the token field: it is a secret, valid once.

=== Request

GET /auth/invitations
Authorization: Bearer <token>

=== Response 200 OK

[
  { "email": "bob@example.com",   "role": "member", "isNewUser": true,  "createdAt": "2026-01-01T00:00:00Z", "expiresAt": "2026-01-08T00:00:00Z" },
  { "email": "carol@example.com", "role": "member", "isNewUser": false, "createdAt": "2026-01-02T00:00:00Z", "expiresAt": "2026-01-09T00:00:00Z" }
]

=== Server-side steps

  1. Read the caller’s active team via MembershipProvider.activeMembership(userId).

  2. Query auth_invitations for all non-expired documents matching the active teamId.

  3. Exclude the token field from the response projection.

  4. Return 200 OK.

Disabled when accountsConfig.membership-endpoints-enabled: false.

== List team members

GET /auth/team/members: requires authentication.

Returns the members of the caller’s active team: email, name, role and joinedAt, with the name read from each member’s profile. The caller cannot ask for another team. Every member of the team can read the list, an owner and a regular member alike.

=== Request

GET /auth/team/members
Authorization: Bearer <token>

=== Response 200 OK

[
  { "email": "alice@acme.com", "name": "Alice Rossi", "role": "owner",  "joinedAt": "2026-01-01T00:00:00Z" },
  { "email": "bob@acme.com",   "name": "Bob Smith",   "role": "member", "joinedAt": "2026-01-02T00:00:00Z" }
]

=== Server-side steps

  1. Read the caller’s active team with MembershipProvider.activeMembership(userId). Without an active team: 403 Forbidden.

  2. Call MembershipProvider.listTeamMembers(teamId).

  3. Return 200 OK.

Disabled when accountsConfig.membership-endpoints-enabled: false.

== Remove a member

DELETE /auth/remove-member: requires role owner.

=== Request

DELETE /auth/remove-member
Authorization: Bearer <token>
Content-Type: application/json

{
  "email": "bob@example.com"
}

=== Server-side steps

  1. Authorize the caller (must be owner of their active team).

  2. Verify the target user is a member of the caller’s team, 404 Not Found otherwise.

  3. Prevent the owner from removing themselves (400 Bad Request).

  4. Call MembershipProvider.removeMember(email, teamId).

  5. Return 200 OK.

=== Error responses

Status Reason

400

Missing email field; or owner trying to remove themselves

403

Caller does not have owner role

404

Target user is not a member of the caller’s team

== Update a member’s role

PATCH /auth/member-role: requires role owner.

=== Request

PATCH /auth/member-role
Authorization: Bearer <token>
Content-Type: application/json

{
  "email": "bob@example.com",
  "role":  "member"
}

role must be one of: the configured member-role-name (default "member") or the configured ownership-role (default "owner").

Important
The admin role is a system-level ACL role and cannot be assigned as a team role via this endpoint.

=== Server-side steps

  1. Authorize the caller (must be owner of their active team).

  2. Validate role: it must be memberRoleName or ownershipRole, otherwise 400 Bad Request.

  3. Verify the target user is a member of the caller’s team, 404 Not Found otherwise.

  4. Call MembershipProvider.updateMemberRole(email, teamId, newRole).

  5. Return 200 OK.

=== Error responses

Status Reason

400

Missing fields; or role not in [memberRoleName, ownershipRole]

403

Caller does not have owner role

404

Target user is not a member of the caller’s team

== See also

Team lifecycle management (create an additional team, rename/edit, delete) is a separate concern from membership: see Authentication Flows sections 10. Create an Additional Team, 14. Update a Team, and 15. Delete a Team.