Skip to Content
Signet

Organizations

Create organizations, manage memberships and select an active organization.

An Organization is a group of Users sharing membership and roles. Signet stores no organization state itself; you supply an OrganizationStore. The active organization is a signed cookie, not a Session column, so no schema migration is required.

type OrganizationStore interface {
    Create(context.Context, *Organization) error
    List(context.Context, string) ([]*Organization, error)
    AddMember(ctx context.Context, orgID, userID, role string) error
    RemoveMember(ctx context.Context, orgID, userID string) error
    MemberRole(ctx context.Context, orgID, userID string) (string, error)
    SetMemberRole(ctx context.Context, orgID, userID, role string) error
    Members(context.Context, string) ([]*MemberInfo, error)
}

Configure it

cfg.OrganizationStore = myOrganizationStore
cfg.Authorizer = myAuthorizer
cfg.AuthorizeIn = myOrgAwareAuthorizer // optional; re-reads membership per check

With no OrganizationStore the feature is disabled and every operation denies. When OrganizationStore is set but AuthorizeIn is not, Signet installs a built-in policy (signet.NewOrgAuthorizeIn): organizations:member-add, member-remove and member-role go to members holding one of the configured membership roles — the organization's owner and admin roles by default, or the roles named in Config.OrganizationRoles if your vocabulary differs — with membership re-read on every check. Wire AuthorizeIn explicitly to override it. All mutations require a Session within Accounts.FreshWindow (passed as SessionToken) plus the published permission; each emits an Audit event on success and on denial. A stale Session that would otherwise be granted returns 403 session_not_fresh — sign in again and retry — not the generic 403 forbidden a permission denial produces; a missing organization_id returns 400 invalid_input.

Create and manage memberships

created, err := auth.CreateOrganization(ctx, signet.CreateOrganizationInput{
    OwnerID: userID, SessionToken: sessionToken, Name: "Acme",
})
// CreateOrganizationResult carries the Organization.

listed, _ := auth.ListOrganizations(ctx, signet.ListOrganizationsInput{
    UserID: userID, SessionToken: sessionToken,
})
// ListOrganizationsResult carries []*Organization.

err = auth.AddOrganizationMember(ctx, signet.AddOrganizationMemberInput{
    OrgID: created.Organization.ID, UserID: memberID, Role: "member",
    ActorID: userID, SessionToken: sessionToken,
})
// Or resolve an existing User by email instead of User ID.
err = auth.AddOrganizationMember(ctx, signet.AddOrganizationMemberInput{
    OrgID: created.Organization.ID, Email: "member@example.com", Role: "member",
    ActorID: userID, SessionToken: sessionToken,
})
members, _ := auth.ListOrganizationMembers(ctx, created.Organization.ID, userID, sessionToken)
// ListOrganizationMembersResult carries []*MemberInfo (User ID, role, name and
// email). Name and Email resolve from the application Store at read time and
// are empty when the membership references a User the Store no longer has.

err = auth.SetOrganizationMemberRole(ctx, created.Organization.ID, memberID, "admin", userID, sessionToken)
err = auth.RemoveOrganizationMember(ctx, created.Organization.ID, memberID, userID, sessionToken)

Exactly one of UserID and Email is required: sending both or neither returns 400 invalid_input, and an email with no matching User returns 404 user_not_found. Email lookup uses the same normalized form as sign-up. This resolves an existing User — no invitation email is sent, and someone without an account must sign up first. Calling a member endpoint without organization_id returns 400 invalid_input.

Creation requires PermissionOrgsCreate; member changes require PermissionOrgsMemberAdd, PermissionOrgsMemberRole and PermissionOrgsMemberRemove — and listing Members requires the same organizations:member-add grant, so only owners and admins see member names and emails. Organization-scoped checks re-read membership from OrganizationStore and consult AuthorizeIn.AuthorizeIn with the organization ID — the wired policy, or the built-in policy when none was configured. The plain global Authorize is consulted only by that fallback path.

Active organization

err := auth.SetActiveOrganization(ctx, signet.SetActiveOrganizationInput{
    OrgID: created.Organization.ID, UserID: userID, SessionToken: sessionToken,
})
active := auth.ActiveOrganizationFromRequest(r) // *ActiveOrganization
auth.ClearActiveOrganization(w)                  // expires the cookie

SetActiveOrganization verifies membership in the store before the cookie is written. The HTTP endpoints are POST /set-active-organization, GET /active-organization (anonymous, returns {"id":"..."}) and POST /clear-active-organization. A tampered or stale cookie is treated as absent and never grants membership.

HTTP endpoints

MethodPathDescription
GET/organizationsList the caller's Organizations
POST/organizationsCreate an Organization
GET/organization-members?organization_id=…List Members
POST/organization-members/addAdd a Member
POST/organization-members/removeRemove a Member
POST/organization-members/roleChange a Member's role
POST/set-active-organizationSelect an Active organization
GET/active-organizationRead the Active organization
POST/clear-active-organizationClear the Active organization

All endpoints derive the actor from the session cookie; an impersonation cookie, when present, supplies the administrator ID. See Authorization for the permission model.

ListOrganizationMembersInput selects an Organization and the requesting User.

On this page