Principals
A principal is anyone who signs in to your product: a human, an agent, one of your own backends, or a guest. Every principal has one kind of ID, prn_…, and goes through the same access checks, so a role, a grant, a check, or an event names a principal the same way whatever it is.
Kinds
A principal may declare a kind: human, agent, or service. The kind is a label. A principal may leave it unset, and may change or clear it at any time with PATCH /me, or your server with PATCH /principals/{id}. Roles, grants, invitations, sign-in methods, and access checks treat every kind alike.
The one kind IdentityHound sets itself is guest, for someone using your product before signing in. Guests describes them. A setting that says who may hold or accept something, such as a role’s assignableTo, tells apart only guest and principal, every principal that is not a guest.
A principal’s displayName and avatarUrl are optional. IdentityHound creates a principal without either field at sign-up. A provider’s display name, login, and picture stay on the sign-in identity’s profile, which GET /me/identities answers with. To start a principal with the provider’s name and picture, copy them with a profile patch, or turn on the SDK’s profileFromProvider. Your app decides what to show when there is no name, such as an email address it already has. Send displayName: null in a profile patch to clear it.
Ways to sign in
A principal signs in with an emailed code, an OAuth provider, such as Twitch, or an API key, and may hold any mix of them. Each email address and each provider login is a sign-in identity linked to one principal, and a principal may hold several. Any principal that is not a guest may add an email address with POST /me/identities/email or link a provider login. Sessions says what a sign-in starts.
A principal other than a guest keeps at least one way to sign in that works with no further action: a sign-in identity your config accepts, or an API key with no expiry. Removing the last one, by removing an identity or revoking a key, answers last_sign_in_method. Add another way first.
Signing up
The first sign-in with an emailed code or a provider creates the principal when the config’s sign-up mode allows it: open, which a new project starts with, lets anyone sign up; invite_only lets a principal sign up with an emailed code for an address with a pending, unexpired email invitation; closed lets nobody. IdentityHound emails a sign-in code only to an address that has an account or that the mode lets in, so a closed project sends no mail to strangers. The sign-in may declare a kind; without one, the new principal has none. Your server can also import principals with their identities.
Each identity that joins a principal is an identity.linked event, whose reason says how: sign_up, upgrade for a guest that signs in, import, added for one added to a principal that already existed, or merged.
Merging accounts
Signing up separately with two new sign-in identities creates two principals. Two accounts join only when a principal proves it holds both, by signing in to one and linking a sign-in method held by the other, through an OAuth link or a code that verifies an added email. IdentityHound never joins accounts by matching email addresses or other profile data.
A new project’s config sets accounts.merge to off. With off, linking a method another principal holds fails with identity_in_use and no merge offer, and the merge operation refuses. With on, the same failure offers a merge when both accounts are active principals, neither a guest, in the same project and environment. Its details holds mergeTicket, expiresAt, and heldBy, the other account’s ID. A ticket lasts the config’s accounts.mergeTicketTtl, 10 minutes in a new project, works once, and works only for the signed-in principal it was issued to.
Linking moves nothing. Your app asks whether to merge the other account into the one signed in. Only after that answer does it send { mergeTicket } to POST /me/merge. The SDK workflow holds the offer and waits for that confirmation.
The signed-in account survives. The other account’s sign-in identities and grants move over. Its connections, roles, and memberships follow the rules below. For a connection with the same provider app and login on both accounts, the survivor keeps its own. A project role moves only if the survivor may still hold it. When both accounts belong to one workspace, the merged account keeps the higher access of the two: an active membership over a suspended one, then an owner over any other role when both memberships have the same status. When neither is higher, the survivor’s membership stays. IdentityHound ranks no other roles, since what they mean is your app’s. When both hold the same role on a resource in the same workspace or both outside any workspace, the survivor’s stays. It keeps the later expiry, or no expiry if either role has none. The other account’s sessions end, and its record stays with status: deleted and mergedInto naming the survivor, so your app can resolve its old ID. Send security notices tells both accounts about the merge.
A merge answers merge_blocked with details.blockers when the other account holds an active, unexpired API key, or is a party to an active, unexpired delegation. It is blocked too when both accounts hold the same role on a resource but in different workspaces, or one in a workspace and one outside any, since a principal holds a role on a resource once; the blocker names the other account’s resource role. A merge that adds workspace ownership beyond workspaces.maxOwnedPerPrincipal is blocked as well. End the listed key or delegation, remove one of the two resource roles, or resolve the owner limit before confirming again. A workspace the other account solely owns can move; being its sole owner does not block the merge.
IdentityHound moves only the data it holds. Your app processes principal.merged from the change feed to move its own records, balances, and progress. The event names the survivor as principalId, the old account as mergedId, its kind, when set, as mergedKind, both accounts’ display names, when set, as displayName and mergedDisplayName, and the identities, connections, grants, resource roles, project roles, and workspaces that moved.
Creating a principal
Your server, or any signed-in principal that is not a guest, creates a principal with POST /principals, such as an agent your product runs or one of your own backends. The answer holds the new principal, its first API key’s record, apiKey, and that key’s secret, token, agp_ak_…, shown only in this answer. The new principal records its creator in createdBy. Creating a principal gives the creator no authority over it: to act for it, or to have it act for the creator, one principal delegates to the other, or a workspace role covers it.
An agent acts as itself through the roles it holds, or for another principal through a delegation.
Who manages a principal
Only the principal itself, with its own session or API key, or your server, with the secret key, changes a principal: updates its profile, issues, rotates, or revokes its API keys, suspends it, or deletes it. A suspended principal can’t sign in, so your server reactivates it.
A restricted API key does none of that, since no access check would hold it to its restrictions. It only manages keys: it issues, rotates, or revokes a key restricted to its own workspaces and permissions or fewer, itself included. Any other change it tries to its principal answers forbidden.
API keys
Any principal that is not a guest may hold API keys, agp_ak_…, each shown only in the answer that issues it. A key may carry restrictions, the workspaces and permissions it works in, which cap what it can do whatever its roles or delegations allow, and an expiry. An access check outside those restrictions answers credential_restricted.
When you rotate a key, send grace to choose how long the old key keeps working, up to seven days. Send 0s to stop it at once. The old key still stops at its expiry if that comes first. A key is replaced once. Asking for another replacement, including in a concurrent rotation, answers conflict, so rotate its replacement instead.
Guests
A guest is someone using your product before signing in. It has a stable ID and one session, and no sign-in identity. It can hold resource roles and grants, and join a workspace in a role whose assignableTo lists guest. It can’t create a workspace or a principal, hold an API key, add a sign-in identity, delegate, or receive a delegation.
- Off in a new project. To turn guests on, read the config, set
guests.enabledtotrue, and send the whole config back. The config caps guests atguests.createPerIpPerHournew guests per IP address per hour, 30 in a new project, and atguests.maxActivelive guests when set. Configure your project shows the calls. - Signing in with a new identity keeps the guest’s access records. Pass the guest’s session when verifying the code or finishing OAuth. When sign-up is allowed, the guest becomes a principal that is not a guest, in place, with the same ID, grants, resource roles, and memberships, and the kind the sign-in declared, or none. Its guest session ends, and a new session begins.
- Merging moves it to another principal. A principal that signed in on its own merges a guest into itself once, with the guest’s session token, through
POST /me/merge-guest. The guest’s grants, resource roles, and memberships move over, its session ends, the guest is deleted, and theprincipal.mergedevent tells your app to move its own data. The same resource-role clash that blocks a merge between two accounts also blocks a guest merge. - An ended guest is deleted. After its session ends, including by sign-out, IdentityHound deletes the guest in a background sweep, revokes its active grants, and removes its resource roles and memberships.
Status
A principal is active, suspended, or deleted, and only an active one can sign in or pass an access check.
- Suspending stops every way the principal acts: its sessions end, the delegated tokens it holds as a delegate end, its API keys stop working, and every requested and active delegation it is a party to is revoked. Reactivating lifts the suspension. Its API keys work again; no session or delegation comes back.
- Deleting ends its sessions and delegations as suspension does, and revokes its API keys. It removes the principal’s sign-in identities, connected accounts, memberships, and resource roles, and keeps the principal record with
status: deleted.
Suspending or deleting a principal whose active owner membership is the last one in an active workspace answers last_owner. Give another member the owner role first.
Limits
displayName, when supplied: 1 to 120 characters.externalRef, your own ID for the principal: 1 to 200 characters, unique in the project.- An import: 1 to 500 principals.
Where to act on it
- Let one principal act for another creates a principal with its key.
- Send security notices tells a principal when a sign-in method, connection, or API key is added, or two accounts merge.
- Principals creates, lists, imports, suspends, and deletes principals, and API keys issues and rotates keys.
- The signed-in principal covers a principal’s own profile, identities, and sessions, and merges a guest or another account.