identity

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 21 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package identity holds the rules of managing the people of one auth: creating a person, disabling one and ending their sessions, seating one in a role. An application does not call it directly. The code generator writes, for every auth an application declares, the resources over the auth's own tables and the methods that change them; each method's body is one call into this package, so the rules are compiled and tested once and are the same for every auth of every application.

How a tenant comes to exist is among the rules. Nobody creates a tenant directly: staff of the auth a tenant is made through invite one person with the tenant's details (Manager.InviteTenant, the details held to the tenant record's own create for the sender by Manager.CheckInvitedTenant), and that person's first sign-in makes the tenant through the application's generated maker (TenantMaker), seats them with the roles that administer a tenant and, where they came through their organization's directory, makes it the tenant's own, in the transaction that consumes the invitation. Manager.InvitedTenants lists the invitations that still stand, and Manager.WithdrawTenantInvitation withdraws one.

Every rule runs inside the caller's transaction (resource.ReadWriteTransaction): a generated handler's, or one an application opened to create a person beside its own rows and commit them together. Nothing here commits, and nothing reads a row a sibling call buffered in the same transaction, which Spanner applies only at the commit: a rule takes what it needs from its caller.

The sign-in paths do not come through here. The session library reads and writes the same tables in its own storage, on its own transactions, and is unchanged by this package; what couples the two is the schema, the few rules both hold (each marked "shared rule" where this package holds its half), and the word to the permission engine once a membership is committed.

Index

Constants

View Source
const EndedByItself = "the assignment ended by itself"

EndedByItself is the source a removal carries when nobody made it: the assignment's period ended, and the row is removed at the person's next sign-in. A change record of the row, where the application keeps one, says so in place of a person's act.

PasswordWay is the key of the password among the ways a person signs in (SignInWay.Key): the name the password method is registered under.

Variables

This section is empty.

Functions

func GroupID added in v0.5.0

func GroupID(id impulse.UUID) accesstypes.Group

GroupID answers a group as the permission store names it: the id of its row, as text.

func PersonNamed added in v0.5.0

func PersonNamed(list accesstypes.Resource, named []resource.Condition) (userID impulse.UUID, ok bool, err error)

PersonNamed reads the one person a list kept per person was asked about, from the conditions the request's filter holds on the person's id (resource.FilterShape.Take): one equality. Such a list answers about one person at a time and holds no rows for a request that names nobody, for which ok is false. A request that names people any other way, by a set, a range or two conditions, is refused with what to send.

func RequestPeriod added in v0.5.0

func RequestPeriod(startsAt, endsAt *time.Time) (accesstypes.Period, error)

RequestPeriod answers the period a request's two optional times name, each nil for none: the start is the first instant an assignment counts and the end the first it no longer does. A period that ends at or before its start never counts and is a Bad Request. The generated methods that give a role, a place in a group or a group's role build their period with it.

func Scope

func Scope(domain *string, everyDomain bool) (accesstypes.PolicyScope, error)

Scope answers the scope a membership is asked for in: one domain when domain names one, every domain when everyDomain is set, the global scope otherwise. Naming a domain and every domain together is refused, and so is an empty domain: a request says which it means.

func User added in v0.5.0

func User(userID impulse.UUID) accesstypes.User

User answers a person as the permission store names them: the id of their account, as text. A username can change, and two auths over one database can each hold the same one; an account's id does neither, so a membership, a session's principal and the subject of a row condition all carry it, and the username is what people read.

func UserID added in v0.5.0

func UserID(user accesstypes.User) (userID impulse.UUID, ok bool)

UserID answers the account a permission store's user names; ok is false for a user that is no account's id (the actor of a session that acts as a role from another application, who has no account here).

Types

type EmailChange

type EmailChange struct {
	Address *string
}

EmailChange is the address a change writes on a user row: Address, nil for none.

type Group added in v0.5.0

type Group struct {
	Kind   string
	Axis   string
	Domain string
	Name   string
}

Group is a group of people as the rules read it: where it is kept, in the stores' encoding of a scope, and its name.

type GroupPeriods added in v0.5.0

type GroupPeriods struct {
	Members map[accesstypes.User]accesstypes.Period
	Roles   map[access.GroupRoleKey]accesstypes.Period
}

GroupPeriods is the periods of a group's members and of the roles it holds.

type GroupPlace added in v0.5.0

type GroupPlace struct {
	ID     impulse.UUID
	Kind   string
	Axis   string
	Domain string
}

GroupPlace is one group a person is in, with where the group is kept.

type GroupStore added in v0.5.0

type GroupStore interface {
	// InsertGroup buffers a new group and answers the id the row is created under.
	InsertGroup(ctx context.Context, txn resource.ReadWriteTransaction, group *access.GroupRow) (impulse.UUID, error)
	// Group reads a group; found is false where no group holds the id.
	Group(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (group *Group, found bool, err error)
	// GroupNamed reports whether a group is kept in the place under the name.
	GroupNamed(ctx context.Context, txn resource.ReadWriteTransaction, place *access.GroupRow) (bool, error)
	// DescribeGroup buffers a new description on a group.
	DescribeGroup(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, description string) error
	// DeleteGroup buffers the removal of a group's row.
	DeleteGroup(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
	// TenantGroups lists the groups kept in one tenant.
	TenantGroups(ctx context.Context, txn resource.ReadWriteTransaction, domain accesstypes.Domain) ([]impulse.UUID, error)

	// GroupMembers lists the people in a group, each by the id of their account.
	GroupMembers(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) ([]accesstypes.User, error)
	// HasGroupMember reports whether the member row is committed.
	HasGroupMember(ctx context.Context, txn resource.ReadWriteTransaction, key *access.GroupMemberKey) (bool, error)
	// InsertGroupMember buffers a member row unless the person is in the group already,
	// committed or written earlier in this transaction, and reports whether it did.
	InsertGroupMember(ctx context.Context, txn resource.ReadWriteTransaction, key *access.GroupMemberKey) (inserted bool, err error)
	// DeleteGroupMember buffers the removal of a member row.
	DeleteGroupMember(ctx context.Context, txn resource.ReadWriteTransaction, key *access.GroupMemberKey) error
	// UserGroups lists the groups a person is in, each with where it is kept.
	UserGroups(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) ([]GroupPlace, error)

	// GroupRoles lists the roles a group holds, wherever each is held.
	GroupRoles(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) ([]access.GroupRoleKey, error)
	// HasGroupRole reports whether the row of a group's role is committed.
	HasGroupRole(ctx context.Context, txn resource.ReadWriteTransaction, key *access.GroupRoleKey) (bool, error)
	// InsertGroupRole buffers the row of a group's role unless the group holds the role
	// there already, and reports whether it did.
	InsertGroupRole(ctx context.Context, txn resource.ReadWriteTransaction, key *access.GroupRoleKey) (inserted bool, err error)
	// DeleteGroupRole buffers the removal of the row of a group's role.
	DeleteGroupRole(ctx context.Context, txn resource.ReadWriteTransaction, key *access.GroupRoleKey) error
	// TenantGroupRoles lists every role a group holds in one tenant, whichever group
	// holds it: the rows of the group roles table under the tenant's own scope.
	TenantGroupRoles(ctx context.Context, txn resource.ReadWriteTransaction, domain accesstypes.Domain) ([]access.GroupRoleKey, error)
	// GroupsHolding lists the groups whose row says they hold the role where the key
	// says it is held, whatever the row's period: the rows of the group roles table
	// under that scope and role.
	GroupsHolding(ctx context.Context, txn resource.ReadWriteTransaction, key *access.RoleKey) ([]impulse.UUID, error)

	// TenantPerson reports whether the account is one of a tenant's people: a row of the
	// tenant's own list of the auth's people, the list a tenant's method names a person
	// from, read in the transaction. An auth of an application with no tenant record
	// has no such list and finds nobody.
	TenantPerson(ctx context.Context, txn resource.ReadWriteTransaction, domain accesstypes.Domain, userID impulse.UUID) (bool, error)
}

GroupStore is what the group rules need of one auth's tables: single reads and single buffered writes over the groups, their members and the roles they hold, which the generated package of the auth implements over its own typed queries and patches. An auth whose schema holds no group tables, or whose roles a directory writes, answers that it keeps none.

type HeldImpersonation

type HeldImpersonation struct {
	// SessionID is the session the record belongs to.
	SessionID impulse.UUID
	// ActsAsRole marks a record whose session acts as a role: such a session carries
	// the actor's own username, where one that views as a user carries that user's.
	ActsAsRole bool
}

HeldImpersonation is one standing impersonation record a person holds as its actor.

type Invitation

type Invitation struct {
	// Email is the address the invitation is mailed to.
	Email string
	// Name is the name the sender gives the person, nil for none. Whoever accepts the
	// invitation takes it where their account holds no name: a new account that the
	// sign-in asserts no name for, and an existing one without a name.
	Name *string
	// Domain is the tenant the roles are held in, nil for an invitation into the
	// application: a role of the global scope is then held there, and a role of the
	// domain kind in every tenant.
	Domain *string
	// Roles are the roles the acceptance gives: at least one.
	Roles []accesstypes.Role
}

Invitation is an invitation to send: an address, and the roles whoever accepts it is given.

type InvitedTenant added in v0.5.0

type InvitedTenant struct {
	// ID is the invitation's id, Email the address it was mailed to, and Name the name
	// its sender gave the person, "" for none.
	ID    impulse.UUID
	Email string
	Name  string
	// TenantName is what people will call the tenant.
	TenantName string
	// DirectoryOnly says the tenant will be entered through its directory only.
	DirectoryOnly bool
	// DefaultRole is the role a person from the tenant's directory starts with, "" for
	// none.
	DefaultRole string
	// Fields are the tenant record's fields as staff entered them (NewTenant.Fields).
	Fields json.RawMessage
	// InvitedByUserID is the user who sent it, null when unknown.
	InvitedByUserID impulse.NullUUID
	// CreatedAt is when it was sent, ExpiresAt when it stops standing.
	CreatedAt time.Time
	ExpiresAt time.Time
}

InvitedTenant is an invitation that makes a tenant and still stands, as staff see it.

type InvitedTenantRow added in v0.5.0

type InvitedTenantRow struct {
	ID              impulse.UUID
	Email           string
	Name            string
	NewTenant       string
	InvitedByUserID impulse.NullUUID
	CreatedAt       time.Time
	ExpiresAt       time.Time
}

InvitedTenantRow is an invitation that makes a tenant as the store reads it off the mail links table: the row's own columns, and the document its NewTenant column holds (session.InvitationRow.NewTenantColumn), which the manager reads.

type Link struct {
	ID         impulse.UUID
	Method     sessioninfo.AuthMethod
	Connection string
}

Link is one identity linked to a user, as the rules read it: its id, and the sign-in method and the connection it came through (the identities table's Method and Connection), which say whether a sign-in through it is still possible.

type MailLink struct {
	// Invitation says the link is an invitation (the others are an address's
	// verification and a sign-up).
	Invitation bool
	// Consumed says the link was followed or withdrawn, and ExpiresAt is when it stops
	// being accepted.
	Consumed  bool
	ExpiresAt time.Time
}

MailLink is a link the auth mailed, as the rules read it.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager applies the rules to one auth: over the store of its tables, with the permission engine that reads its memberships.

func New

func New(auth string, store Store, controller access.Controller, sessions SessionAPI, opts ...Option) (*Manager, error)

New returns the manager of one auth. auth is the auth's name, the one its outlets' generated routes bind to a request (the auth package's Name): the rules that keep a person from acting on themselves take a caller for a person of this auth only when the request came through it. controller is the permission engine the auth's memberships are read by: the rule a membership's role is held to is its own (access.UserManager.Membership), and it is told once a membership is committed. sessions is the API of the session library's Auth that signs the auth's people in.

func (*Manager) AddGroupMember added in v0.5.0

func (m *Manager) AddGroupMember(ctx context.Context, txn resource.ReadWriteTransaction, groupID, userID impulse.UUID) error

AddGroupMember is AddGroupMemberFor with no period: the person is in the group until they are taken out, and a place they had for a period loses the period.

func (*Manager) AddGroupMemberFor added in v0.5.0

func (m *Manager) AddGroupMemberFor(ctx context.Context, txn resource.ReadWriteTransaction, groupID, userID impulse.UUID, period accesstypes.Period) error

AddGroupMemberFor buffers a person's place in a group, in the caller's transaction, and has the permission engine told once the transaction has committed, so the person's next request is served with the group's roles. The person is named by the id of their account and is not looked up, as AssignRole looks nobody up. A group holds any account, also a person who holds roles in other tenants.

The place is given for the period: the person holds the group's roles while their place and the group's role both count, and a person who is in the group already is given the period handed in place of the one their place had. AddGroupMember gives the place with no period.

Where a person belongs to one tenant (WithOneTenantPerPerson), a place in a tenant's group is a role in that tenant: it is refused for a person who holds a role, or a place in a group, in another one (refuseSecondTenant).

A request that puts a person in a group gives them each role the group holds, and needs what giving them each role directly needs (refuseGivingThrough). And nobody lengthens their own holding: the caller does not give their own place a period that lasts longer than the one it has (refuseLongerForOneself).

func (*Manager) AdministratorsEnterWithPassword added in v0.5.0

func (m *Manager) AdministratorsEnterWithPassword() bool

AdministratorsEnterWithPassword reports whether a tenant's own administrators of this auth keep a way into a tenant that is directory only: the auth registers the password method and its permission engine names the roles that administer a tenant. The warning of the method that turns the switch on says so to the person about to turn it (resource.DirectoryPeople).

func (*Manager) AnyMethodOpen added in v0.5.0

func (m *Manager) AnyMethodOpen(ctx context.Context, reader resource.ReadOnlyTransaction) (bool, error)

AnyMethodOpen reports whether an administrator has some sign-in method of the auth open to sign-up now, for the audience the method has. In an application with tenants it is what lets a person who holds no tenant create one: a person who signed up through an open method, and nobody while every method is invite only. A row of a method the auth no longer registers opens nothing, and neither does one opened for another audience than its registration has now.

func (*Manager) AssignRole

AssignRole is AssignRoleFor with no period: the membership stands until it is removed, and one the person held for a period loses the period.

func (*Manager) AssignRoleFor added in v0.5.0

AssignRole buffers the membership that says the person holds the role in the scope, in the caller's transaction, and has the permission engine told once the transaction has committed, so the person's next request is served with the role. The person is named by the id of their account, the engine's name for them (User), and is not looked up: a user created earlier in the same transaction is not readable until the commit, and the caller holds the id. A membership the person holds already is left as it is.

"Holds already" is what the database has committed and what this transaction's own patches have written: the store writes the row as a create-unless-there (the generated patch's OrSkip), which asks the transaction's record of the rows it wrote before it reads the stored row, since no read sees a buffered write. So a second call for one membership in one transaction is left as it is too. That record belongs to the library transaction the call is handed. The two hooks of a sign-in each wrap the session's transaction on their own and share none, which is why the session library keeps a default role the accepted invitation names too out of the directory hook's hands.

The rule is the permission engine's (access.UserManager.Membership): the role exists in the scope under exactly this spelling, and the person is somebody (the nil id is refused). A role of the release's role file is known to the engine; a custom role is read from the auth's roles table in the caller's transaction, so a role deleted beside the membership fails one of the two.

Where a person belongs to one tenant (WithOneTenantPerPerson), a role in a tenant is refused for a person who holds a role in another one, as a Conflict that never says which (refuseSecondTenant). A role for the whole application or in every tenant is given whatever the person holds, and its holder is given a role in any tenant.

The Super Administrator role is given in the global scope alone, and by a caller who holds it (requireSuperAdministrator): only a super administrator makes another. A call outside any request is the application's own act and gives it. Giving it ends nothing: the sessions the person holds, their bearer tokens and the browsers remembered for their second factor stand, and the session they are signed in with acts with the role at its next request. A person who is signed in when the role is given is no risk for being signed in; the account is what the role guards, and a second factor is asked for at every sign-in from then on. What an administrator set on the account before the role, a password or an address, is left as it is too: the super administrator who gives the role chooses whom to trust.

The membership is given for the period: it counts from the period's start, where it has one, until its end, where it has one, and a membership the person holds already is given the period handed in place of the one it had (periods.go). Whoever may give the role gives it a period, and the Super Administrator role takes none (access.ValidatePeriod). AssignRole gives the membership with no period. Nobody lengthens their own holding: a caller who may give the role does not give their own membership a period that lasts longer than the one it has, and someone else who may give it does (refuseLongerForOneself).

func (*Manager) CallerPassword added in v0.5.0

func (m *Manager) CallerPassword(ctx context.Context, txn resource.ReadWriteTransaction) (has, applies bool, err error)

CallerPassword answers whether the person behind the request holds a password in this auth, for the rule that a tenant is made directory only by a person who has a password, their way back in if the directory has a problem (resource.TenantDirectoryRules.PasswordsBy; it is a resource.CallerPassword). applies is false where the rule asks nothing of this auth: a call outside any request, a request that came through another auth, whose caller is nobody of this one, and an auth that registers no password method, where nobody could have a password and the rule stands down. The person is the real one behind the session, never one it views as; one with no account here has no password here.

func (*Manager) CheckInvitedTenant added in v0.5.0

func (m *Manager) CheckInvitedTenant(ctx context.Context, client resource.Client, inv *TenantInvitation) error

CheckInvitedTenant holds the details of a tenant invitation to the rules the tenant record's create applies, for the request's caller, before the invitation is sent: the tenant is made exactly as the acceptance will make it, armed with the caller, in a transaction of its own that is rolled back. A caller without the Create grant on the tenant record, or on a field the details name, is refused as the record's create would refuse them (Forbidden), and so is a detail a condition on the grant does not admit. Nothing is written, and nothing is owed after it.

It runs outside the transaction that writes the invitation: the generated method calls it first. A call outside any request is the application's own act and is held to nothing here.

func (*Manager) ClearEnded added in v0.5.0

func (m *Manager) ClearEnded(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) (int, error)

ClearEnded buffers the removal of the person's assignments whose period has ended: their own memberships and their places in groups. It answers how many rows go.

What has ended is the database's to say, by its own clock, the one the lists and the sign-in rule read (EndedAssignments): a server whose clock runs fast removes nothing that still counts. The read that decides runs in the caller's transaction, the one that buffers the removals, so a row is removed by the transaction that read it as ended: the database fails the commit of a transaction whose read a concurrent change of the period made stale, and a period that has ended stays ended.

It is nobody's act, so the rules of a removal do not judge it. It removes the ended rows and nothing else: the account stays, also when the ended assignment was the last thing the person held; the rule on a tenant's last administrator is not asked, since an ended role administers nothing; each row goes under the source EndedByItself; and the permission engine is told nothing, since an ended assignment already counts for nothing and no instance has anything to reload.

func (*Manager) ClearTenant added in v0.5.0

func (m *Manager) ClearTenant(ctx context.Context, txn resource.ReadWriteTransaction, domain accesstypes.Domain) error

ClearTenant buffers the removal of everything the auth holds for a tenant, in the transaction that deletes the tenant's row, so a tenant that goes leaves nothing of itself in the auth's tables:

  • every membership held in the tenant, whoever holds it;
  • every group kept in the tenant, with its members and the roles it holds, and every role a group kept for the whole application holds in the tenant;
  • every custom role made in the tenant, with its grants;
  • every invitation into the tenant that still stands, withdrawn as WithdrawInvitation withdraws one, so no link admits a person into a tenant that is gone.

A person the tenant's memberships and the places in its groups were the only things held by then holds no role anywhere and no place in a group, and is deleted with their identity links and sessions in the same transaction, by the rule on an account nothing admits (deleteWithLastRole). A person who holds a role anywhere else stays, and so does a role held in every tenant, which is no one tenant's.

The generated delete of the tenant record calls it for each auth whose management the program generates, before the transaction commits; the permission engine is told once it has. Everything is read before anything is buffered. A tenant the auth holds nothing for is no error.

func (*Manager) CreateGroup added in v0.5.0

func (m *Manager) CreateGroup(ctx context.Context, txn resource.ReadWriteTransaction, scope accesstypes.PolicyScope, name, description string) (impulse.UUID, error)

CreateGroup buffers a new group of people kept in the scope, in the caller's transaction, and answers its id. The group is held to the permission store's rules (access.NewGroup): it is kept for the whole application or in one tenant, and carries a name and a description. A name another group kept in the same place holds is refused, as committed; the table's unique index stands behind the read. A new group has no member and holds no role, so nobody's permissions change.

func (*Manager) CreateUser

func (m *Manager) CreateUser(ctx context.Context, txn resource.ReadWriteTransaction, account *NewAccount) (impulse.UUID, error)

CreateUser buffers a new user and the memberships that give them their roles, in the caller's transaction. Without a password the person signs in through a directory, or follows an invitation and chooses their own; with one (NewAccount.Password) it is a temporary password, which the person changes before anything else is served. In an application whose tenants have directories, the sign-in that first links such an account, on the name the directory asserts, is made through the directory of the one tenant the person belongs to or with their own invitation (the session library's rule on a first link made on a name alone): a person created in two tenants, or holding a role in every tenant or outside them, is invited or given a temporary password. It answers the id the row is created under, so the caller may write its own rows beside it before anything is committed. A username or an address another user holds is refused by the table's unique indexes when the transaction commits.

A person is created holding a role: an account that holds no role anywhere is not kept (RemoveRole deletes one with its last role), so none is created without one. Every role is held in the one scope and is held to the rule a role assigned later is (AssignRole): it exists there under exactly this spelling.

Shared rule: an address is written bare, the part a message is sent to, as the session library writes one (its address function); a value that is no address is refused. A name is held to the session library's rule of one (sessioninfo.CleanName): without the space around it, none where nothing is left, refused where it is too long.

func (*Manager) DeleteGroup added in v0.5.0

func (m *Manager) DeleteGroup(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID) error

DeleteGroup buffers the removal of a group, in the caller's transaction, and has the permission engine told once the transaction has committed. A group that still has a member or holds a role is refused until it is emptied: nobody loses a role because a group was deleted, each person is removed and each role taken by an act of its own. The members and the roles are read as committed. A member or a role whose period has ended gives nobody anything: it does not stand in the way, and its row goes with the group. One whose period has not begun stands in the way like one that counts.

func (*Manager) DeleteUser

func (m *Manager) DeleteUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error

DeleteUser buffers the removal of a user, in the caller's transaction: every session they hold is ended, their identity links, every membership they hold and their place in every group go, then the row, and the permission engine is told once the transaction has committed. Nobody deletes themselves: the person acting, the real person behind the session, is refused their own account, and a session that views as someone else the account it views as (refuseOwnAccount). A super administrator's account is deleted by a super administrator alone, and the last one who can sign in by nobody (requireSuperAdministrator, refuseLastSuperAdministrator).

Shared rule: the session library's DeleteSessionUser; the memberships are the user management's, which removes every one the person holds with the account.

func (*Manager) DescribeGroup added in v0.5.0

func (m *Manager) DescribeGroup(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID, description string) error

DescribeGroup buffers a new description on a group, in the caller's transaction. An empty description is refused: a group says who is in it.

func (*Manager) DirectoryName added in v0.5.0

func (m *Manager) DirectoryName(directory signin.Directory) (name, label string)

DirectoryName answers what the auth's sign-in registrations call a directory, for a sentence that names it to a person: the name a registration that takes its connection gives it, and the label of the button a person signs in to it with, each "" where the registrations have none (SessionAPI.DirectoryName). It is a resource.DirectoryNamer: the generated frames hand it to the rules of a tenant's directory (resource.TenantDirectoryRules.NamedBy) and to the tenant list (resource.WithDirectoryNames), so a warning, a refusal and a closed tenant's reason say "Lakeside" or "your organization's Microsoft directory" and never a tenant id.

func (*Manager) DirectoryRole added in v0.5.0

func (m *Manager) DirectoryRole(ctx context.Context, txn resource.ReadWriteTransaction, tenant accesstypes.Domain, role accesstypes.Role) error

DirectoryRole holds the role a tenant is opened to its directory's people with to its rules, in the caller's transaction, and writes nothing. The role is given to every person the directory vouches for at their first sign-in through it (DirectorySeated), to people nobody named, so the person who names it is held to what giving it by hand needs:

  • the role exists in the tenant, by the rule a membership's role is held to: a role of the release's role file held in a tenant, or a custom role of this tenant;
  • the caller could give it there directly: the grant of the method that gives a role in the tenant admits it for that role (RoleGrants.MayGive). The grant is asked for no person in particular, since the people are not known yet, so a grant whose condition reads the person a role is given to admits no default role.

A role the caller may not give is Forbidden, and the grant answers before the role is looked for, so the refusal says the same of a role the tenant holds and of one it does not: a caller learns of no role the grant keeps from them. A role the caller could give that the tenant does not hold is a BadRequest. Each is a sentence the person can act on. A call outside any request is the application's own act and is not judged by the grant; a manager a request reaches without the role grants cannot judge it, which is an error and never a pass.

func (*Manager) DirectoryRoles added in v0.5.0

func (m *Manager) DirectoryRoles(ctx context.Context, db resource.Executor, tenant accesstypes.Domain) ([]access.RoleInfo, error)

DirectoryRoles lists the roles a tenant may be opened to its directory's people with, as the dialog that opens it offers them: the roles that exist in the tenant (TenantRoles) that the request's caller could give there directly, by the question DirectoryRole asks of the grant of the method that gives a role (RoleGrants.MayGive, for no person in particular), and no other. A page offers what the caller may do: a role the list leaves out is one DirectoryRole refuses, and one it offers is one DirectoryRole takes. A call outside any request is the application's own and lists every role of the tenant; a manager a request reaches without the role grants cannot judge it, which is an error and never a list.

It is a list's read and is called outside any transaction, with the database to ask in (db). The tenant's roles are read first, as TenantRoles reads them: the permission engine reads the custom ones on a client of its own, and the database refuses such a read under a transaction's context. The grant of a tenant's method may read a row, so the questions are then asked in one transaction of the list's own, which writes nothing.

func (*Manager) DirectorySeated

DirectorySeated answers the session library's hook for a directory's default role (session.Auth.SetDirectoryAdmission): the default role of the tenant whose directory the person signed in through is buffered as a membership of the person in the tenant, in the transaction that links the person's identity to their account, which is their first sign-in through the directory whether the account is made in it or stood before. The role is given to a person who holds no role in the tenant: one who holds a role there, by an invitation or by an administrator's hand, keeps what they hold and is given nothing, so a link that is deleted and made again does not add the default role beside the role the person was given since. A role that cannot be given fails the transaction, so no account is left holding nothing and no link is left that gave nothing.

auth names the Auth in the log line a given role leaves.

The hook's other half answers whether a tenant is the only place a person holds anything, read in the same transaction: the session library asks it before it links an identity, on its sign-in name alone, to an account that has no password and has never signed in, which a tenant's directory vouches for only when the account is the tenant's alone. It reads what places a person anywhere (holds): the roles of their own and their places in groups, one whose period has not begun counted where it will count and one whose period has ended left out. The account is the tenant's alone when all of it is held in the tenant itself and some of it is: a role in another tenant, in every tenant or outside the tenants, or a place in a group kept anywhere else, makes it more than one tenant's, and the link would hand the tenant's directory all of it. It is the fact a tenant's own methods are held to before they change a person's name, address or password (the list's heldElsewhere and heldGlobally).

The hook's third part answers for the deployment's own seed: whether an account is the one a seed created, with no password, for a person who signs in through the registration named, which is the first administrator of an auth whose people sign in through a directory. That person holds roles for the whole application and belongs to no tenant, so no tenant's directory vouches for the account; the deployment does, by the id it seeded the account under (session.SeedUserIDThrough, over the auth's name, the registration and the username), which no request can give an account and which is derived again here. The session library links such an account on its name at the person's first sign-in through that registration, where the registration admits one organization and nobody else.

func (*Manager) DisableUser

func (m *Manager) DisableUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error

DisableUser buffers the disabling of a user and the end of every session they hold (EndUserSessions), in the caller's transaction: once it commits, the person's next request is refused, and so is their next sign-in. The sign-in paths cache neither fact. Nobody disables themselves: the person acting, the real person behind the session, is refused their own account, and a session that views as someone else the account it views as (refuseOwnAccount). A super administrator's account is disabled by a super administrator alone, since it removes one in effect (requireSuperAdministratorFor), and the last super administrator who can sign in is disabled by nobody (refuseLastSuperAdministrator).

Shared rule: disabling a user ends their sessions, which the session library's DeactivateSessionUser does in two commits of its own.

func (*Manager) EnableUser

func (m *Manager) EnableUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error

EnableUser buffers the enabling of a disabled user, who may sign in again once it commits. The sessions that ended when the user was disabled stay ended. A super administrator's account is enabled by a super administrator alone, since it makes one who can sign in (requireSuperAdministratorFor).

func (*Manager) EndImpersonation

func (m *Manager) EndImpersonation(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID) error

EndImpersonation buffers the end of one impersonated session: the session and its record, as EndSession ends them. A session that was established as nobody else has no record and is refused, so the call cannot end a person's own session by mistake; a record that has ended already is left as it is.

Shared rule: the session library's DestroyImpersonatedSession, which acts only where a record stands.

func (*Manager) EndSession

func (m *Manager) EndSession(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID) error

EndSession buffers the end of one session and of its impersonation record, if it has one that still stands, in the caller's transaction: once it commits, the next request that carries the session is refused. A session that has ended already is left as it is, and a session that does not exist is refused.

Shared rule: the session library ends a session and its record together (DestroySession, DestroyImpersonatedSession). A session established from this one, as someone else, is not ended with it, as it is not there.

func (*Manager) EndUserSessions

func (m *Manager) EndUserSessions(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error

EndUserSessions buffers the end of every session a user holds, in the caller's transaction: the sessions that are the user's own, and the sessions the user established as someone or something else, which are found by the user's name in their records since such a session belongs to whoever it acts as. Every record of those sessions that still stands ends with them. A user that does not exist holds none.

Shared rule: the session library's DestroyUserSessions. One thing it does is left to the library: a record still standing beside a session of the user that had ended before (the state a browser that never came back leaves) is ended there the next time that browser returns, and stands for nothing until then, since its session is refused.

func (*Manager) GiveGroupRole added in v0.5.0

func (m *Manager) GiveGroupRole(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID, scope accesstypes.PolicyScope, role accesstypes.Role) error

GiveGroupRole is GiveGroupRoleFor with no period: the group holds the role until it is taken away, and a role it held for a period loses the period.

func (*Manager) GiveGroupRoleFor added in v0.5.0

func (m *Manager) GiveGroupRoleFor(
	ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID, scope accesstypes.PolicyScope, role accesstypes.Role, period accesstypes.Period,
) error

GiveGroupRoleFor buffers the role a group holds in the scope, in the caller's transaction, and has the permission engine told once the transaction has committed, so every person in the group is served with the role at their next request. The role is given for the period, and a role the group holds there already is given the period handed in place of the one it had. GiveGroupRole gives the role with no period.

The rule is the permission engine's (access.UserManager.GroupRole): the role exists in the scope under exactly this spelling; a group kept in one tenant holds roles in that tenant alone; and no group holds the Super Administrator role, which a super administrator gives to one person at a time.

A request that gives a group a role gives it to everyone in the group, and needs what giving it to each of them directly needs (refuseGivingThrough). And nobody lengthens their own holding: a caller who is in the group does not give a role the group holds a period that lasts longer than the one it has (refuseLongerForOneself).

func (*Manager) InvitationAccepted

InvitationAccepted answers the session library's hook for an accepted invitation (session.Auth.SetInvitationAccepted): the roles the invitation carries are buffered as memberships of the person in the transaction that consumes the invitation. An invitation into a tenant gives its roles in that tenant; one into the application gives each role where that role is held, the global scope for a role of the global kind and every tenant for one of the domain kind, as Invite checked when it wrote the invitation. A role that can no longer be given (the role file changed since) fails the transaction: the invitation stands, and a person the sign-in would have created is not created. An invitation that makes a tenant carries no role: its acceptance makes the tenant and seats the person as its first administrator (acceptTenantInvitation).

auth names the Auth in the log line a given role leaves.

func (*Manager) Invite

func (m *Manager) Invite(ctx context.Context, txn resource.ReadWriteTransaction, inv *Invitation, sent func(sent bool)) (impulse.UUID, error)

Invite buffers an invitation in the caller's transaction and has its link mailed once the transaction has committed. It answers the invitation's id. The session library prepares the invitation (the address check, the token, the time the link stands for) and keeps the token, the message and the sender; the row is written here, beside whatever else the transaction writes, so an invitation and the application's own rows are committed together or not at all.

A message cannot be taken back, so it is not sent until the rows are committed: the send is a step after the commit (resource.AfterCommit). sent is told how it went, after the commit and before the transaction's ExecuteFunc returns: true once the message is with the sender, false when it could not be sent, in which case the session library has withdrawn the invitation, so no link stands that nobody holds, and the caller invites again. A transaction that does not commit sends nothing and never calls sent. sent may be nil.

An invitation gives a role, at least one: a person an invitation admits holding no role is deleted by the rule on an account nothing admits. Every role must exist where the acceptance seats it: in the tenant for an invitation into one, and in the global scope or in every tenant for an invitation into the application. The request's caller is recorded as its sender where they are a user of the auth. An invitation that gives the Super Administrator role is written by a caller who holds it (requireSuperAdministrator); the acceptance then gives what it wrote.

Where a person belongs to one tenant (WithOneTenantPerPerson), an invitation into a tenant is refused when a user already holds the address and holds a role in another tenant and none outside the tenants: a Conflict that says the address has an account and never where. An address no user holds is invited, and whoever accepts is held to the rule then (AssignRole).

Shared rule: the session library's Invite, which stores the row and mails the link in its own storage and answers a failed send as an error.

func (*Manager) InviteTenant added in v0.5.0

func (m *Manager) InviteTenant(ctx context.Context, txn resource.ReadWriteTransaction, inv *TenantInvitation, sent func(sent bool)) (impulse.UUID, error)

InviteTenant buffers an invitation that makes a tenant in the caller's transaction and has its link mailed once the transaction has committed, as Invite does for an invitation into a tenant that exists (sent is told how the send went). It answers the invitation's id. The invitation names no tenant and carries no role: whoever accepts it is seated with the roles that administer a tenant (WithAdministratorRoles) in the tenant their first sign-in makes.

The role a person from the tenant's directory starts with gives a role to people later, so it is held to what giving it directly needs: it is a role of a tenant, never the Super Administrator role, and one the request's caller could give a person in a tenant (RoleGrants.MayGive); a role the caller may not give is Forbidden, naming it. A starting role, and directory only, are refused where the application's records keep neither.

Where a person belongs to one tenant (WithOneTenantPerPerson), an address whose account already belongs to a tenant is refused, as an invitation into a second tenant is: a Conflict that says the address has an account and never where.

The details are the caller's to check first (CheckInvitedTenant): this writes them as given.

func (*Manager) InvitedTenants added in v0.5.0

func (m *Manager) InvitedTenants(ctx context.Context, reader resource.ReadOnlyTransaction) ([]*InvitedTenant, error)

InvitedTenants lists the invitations that make a tenant and still stand: sent, not accepted, not withdrawn and not expired, oldest first. reader is the caller's transaction or the application's client.

func (*Manager) MakeInviteOnly added in v0.5.0

func (m *Manager) MakeInviteOnly(ctx context.Context, txn resource.ReadWriteTransaction, method string) error

MakeInviteOnly buffers the choice that makes a sign-in method invite only again, into the caller's transaction: from the commit on, a person with no account needs an invitation. The people who have accounts keep them, with what they hold. It refuses a method the auth does not register and a method whose directory gives the roles; a method that is invite only already is left as it is, and one whose row was opened for another audience, which opens nothing, has its row written closed.

func (*Manager) OpenSignUp added in v0.5.0

func (m *Manager) OpenSignUp(ctx context.Context, txn resource.ReadWriteTransaction, open *SignUp) error

OpenSignUp buffers the choice that opens a sign-in method to sign-up, into the caller's transaction: from the commit on, a person with no account and no invitation who signs in through the method gets an account. It refuses a method the auth does not register, a method whose directory gives the roles and one whose registration carries an account rule of its own. In an application without tenants it refuses a request that names no default role, one whose role is not held for the whole application or is the Super Administrator role, and one whose role the caller may not give a person directly (403): nobody signs up holding nothing, nobody signs up administering the application, and nobody gives through a sign-in method what they could not give by hand. The grant answers before the role is looked for, so a caller who may not give a role is refused the same way whether or not it exists. In an application with tenants (CreatesTenant) it refuses a request that names a role, since a person who signs up there creates a tenant of their own. The row keeps whom the method admits as it is registered now, and opens the method for that audience alone.

func (*Manager) OpenSignUpWarning added in v0.5.0

func (m *Manager) OpenSignUpWarning(ctx context.Context, txn resource.ReadWriteTransaction, open *SignUp) (*resource.Warning, error)

OpenSignUpWarning says what opening the method would do, in the words a person reads before they confirm it, and the words for the button that does it. It writes nothing. It refuses what OpenSignUp refuses of the method, and of a role that is named; a request that names no role yet is answered, since the warning is read while the role is still being picked, and says the role is to be chosen.

func (*Manager) RemoveGroupMember added in v0.5.0

func (m *Manager) RemoveGroupMember(ctx context.Context, txn resource.ReadWriteTransaction, groupID, userID impulse.UUID) error

RemoveGroupMember buffers the removal of a person from a group, in the caller's transaction, and has the permission engine told once the transaction has committed: the person's next request is served without the group's roles. A person who is not in the group is no error.

A place in a group keeps an account as a role of its own does, so the rule on an account nothing admits applies here as it does to a role taken away (RemoveRole): a person left with no role of their own and no place in any group is deleted with their identity links and sessions, in the same transaction. What the person holds is read as committed, and a row whose period has ended keeps the account like any other: an account goes when nothing at all is left of what was given to it (keeps).

Taking a person out of a group takes each of the group's roles from them, so the removal is held to what a role's removal is: a request needs what taking each role from the person directly needs (refuseTakingThrough); a person who takes themselves out keeps a place that makes them the last administrator of a tenant (refuseLastAdministrator); and where a person belongs to one tenant, the last thing they hold outside the tenants stays while they hold roles in more than one (refuseSeveralTenantsLeft). A place whose period has ended gives the person nothing, and goes whoever asks.

func (*Manager) RemovePassword added in v0.5.0

func (m *Manager) RemovePassword(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error

RemovePassword buffers the removal of a user's password, in the caller's transaction: once it commits, a sign-in with the password is refused as a wrong password is, and the person signs in through the identities linked to them. A user keeps the password unless an identity linked to them can sign them in, since with neither they could not sign in at all: an identity counts when the session library says a sign-in through it is possible (SessionAPI.SignsInThrough), so a link left from a sign-in method the Auth no longer offers, or from a connection none of its registrations takes, does not. The rule holds for everyone, the last super administrator among them, whose password is their way back in like anyone's. The mark that the person must change the password goes with it, and the count of failed sign-ins kept under their name is cleared. The sessions the person holds stand, the ones the password established among them, as a removed identity's do. A super administrator's password is removed by a super administrator alone, since it is a way they sign in (requireSuperAdministratorFor).

The identities that rule reads are the committed ones, read in the transaction that removes the password: an unlink in another transaction and this removal are judged one after the other by the database. An unlink of the user's last identity in the same transaction is not seen, as no read sees a buffered write. Remove a person's password and unlink their identity in transactions of their own.

Shared rule: the session library's RemoveSessionUserPassword, with its refusal (sessionstorage.ErrLastSignInMethod) and its judgment of the links that count.

func (*Manager) RemoveRole

RemoveRole buffers the removal of the person's membership of the role in the scope, and has the permission engine told once the transaction has committed. The person is named by the id of their account. A membership the person does not hold is no error, and the role need not exist any more: a membership of a role since deleted is removed like any other.

Two rules of the user management are held here. A person who removes a role from themselves in a tenant is held to the rule on the tenant's last administrator (refuseLastAdministrator). And a person left with no role anywhere and no place in a group is deleted with their identity links and sessions in the same transaction (deleteWithLastRole), whoever removed the role. The Super Administrator role has its own: it is taken away by a caller who holds it, and never from the last holder who can sign in, whoever asks (requireSuperAdministrator, refuseLastSuperAdministrator). Where a person belongs to one tenant (WithOneTenantPerPerson) there is a third: the last role a person holds outside the tenants stays while they hold roles in more than one tenant (refuseLeavingSeveralTenants).

What the person holds is read as committed: a second removal for the same person in one transaction does not see the first, as no read sees a buffered write, so the account is deleted only when one call removes the last role. Remove one role of a person per transaction.

func (*Manager) RenameUser

func (m *Manager) RenameUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, username string) error

RenameUser buffers a new username for a user, in the caller's transaction, and with it what carries the name for people to read: their live sessions, and the standing impersonation records they hold as actor (and the sessions of those that act as a role, which carry the actor's own name). Nothing the person holds follows the name: the permission store names a person by the id of their account, so the roles stay where they are. A name another user holds is a Conflict; the same name in another case is the person's own. A super administrator is renamed by a super administrator alone, since the name is what the person signs in with (requireSuperAdministratorFor).

Shared rule: the session library's ChangeSessionUserUsername, which renames the user, the live sessions and the standing records in one transaction of its own.

func (*Manager) RequirePasswordChange

func (m *Manager) RequirePasswordChange(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error

RequirePasswordChange buffers the requirement that a user change their password: once it commits, every request of theirs is refused, on the sessions they hold and on new ones, until they have changed it. The way out is theirs alone and takes the password they hold, so the requirement is refused for a user who holds none: nothing they could do would lift it. It is required of a super administrator by a super administrator alone: a holder who signs in through a directory and no longer knows the password is shut out by it until someone sets them another (requireSuperAdministratorFor).

Shared rule: the session library refuses the flag on a user without a password where it creates one (CreateSessionUser), and reads it on every request.

func (*Manager) RequireUser added in v0.5.0

func (m *Manager) RequireUser(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error

RequireUser answers NotFound unless a user of the auth holds the id, read in the caller's transaction. A role is held by an account, and AssignRole looks nobody up (it serves a user created in its own transaction), so a method that gives a role to a person named in a request asks this first.

func (*Manager) RevokeToken

func (m *Manager) RevokeToken(ctx context.Context, txn resource.ReadWriteTransaction, tokenID impulse.UUID) error

RevokeToken buffers the revocation of one bearer token, in the caller's transaction: once it commits, the next request that carries the token is refused, since the session library reads the row on every request. A token is revoked by a mark and its row stays. A token that belongs to a device authorization takes its family with it, every token of the authorization that is not revoked yet, the expired ones among them, so no successor of it stays in use. A token that is revoked or expired already is refused as one that does not exist: there is nothing live to revoke.

Shared rule: the session library's RevokeToken, here for any person's token, where the library's own route revokes the caller's.

func (*Manager) RevokeTrustedDevices

func (m *Manager) RevokeTrustedDevices(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) error

RevokeTrustedDevices buffers an administrator's reset of a user's second factor, in the caller's transaction: every browser the person asked to be remembered is forgotten, so their next sign-in from any of them asks for the factor. The sessions that stand are not touched (EndUserSessions ends them).

Shared rule: the session library's ResetFactors.

func (*Manager) RolesToGive added in v0.5.0

func (m *Manager) RolesToGive(ctx context.Context, tenant accesstypes.Domain) ([]access.RoleInfo, error)

RolesToGive lists the roles a person picks from to give one in a tenant by hand, as the dialogs of the methods that give a role offer them: the roles that exist in the tenant (TenantRoles) that the request's caller could give there by one of those methods (RoleGrants.CouldGive), and no other. A page offers what the caller may do: a role the list leaves out is one every such method refuses this caller, whoever it is given to, so a role file says which roles a person hands out once, on the methods' grants, and the list follows. One list serves the pickers of all of them, so it holds a role that one of them takes and another refuses, which the method then says. A call outside any request is the application's own and lists every role of the tenant; a manager a request reaches without the role grants cannot judge it, which is an error and never a list.

It is a list's read, called outside any transaction, and opens none: the question reads no row (DirectoryRoles asks for nobody in particular, which may).

func (*Manager) SetEmail

func (m *Manager) SetEmail(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, email *string) error

SetEmail buffers an address on a user, entered by hand, or takes the address off (nil): an operator's entry, for a person whose address changed or who was created without one. The address is held unverified, whatever the one before it was, and is trusted for nothing until the person verifies it themselves; it reserves the address all the same, so one another user holds is refused by the table's unique index when the transaction commits.

It is for an auth whose usernames are not the addresses: where they are, the address is the username, and it changes when the person verifies a new one.

A super administrator's address is set by a super administrator alone: it is where the code of their second factor is mailed, so whoever sets it receives the code (requireSuperAdministratorFor).

Shared rule: the session library's SetSessionUserEmail, which writes the address bare and clears the time it was verified.

func (*Manager) SetName added in v0.5.0

func (m *Manager) SetName(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, name *string) error

SetName buffers a person's name on a user, or takes the name off (nil, or nothing but space), in the caller's transaction. The name is what pages show for the person in place of the username; it identifies nobody, so nothing follows it: no session ends and no membership moves. A name written here stands until it is written again: a later sign-in through a directory fills a name only where the user holds none.

Shared rule: the session library's SetUserName, which holds the name to the same rule (sessioninfo.CleanName) and writes it on the row.

func (*Manager) SetTemporaryPassword

func (m *Manager) SetTemporaryPassword(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, password string) error

SetTemporaryPassword buffers a password an operator chose for a user, in the caller's transaction: the person must change it before anything else is served, every session they hold is ended, and the count of failed sign-ins kept under their name is cleared, so a person locked out signs in with the new password at once. The hash is the session library's, made by the password method's hasher. A super administrator's password is set by a super administrator alone: whoever sets it signs in as them (requireSuperAdministratorFor).

Shared rule: the session library's ResetSessionUserPassword, which does the same in commits of its own.

func (*Manager) SignInMethods added in v0.5.0

func (m *Manager) SignInMethods(ctx context.Context, reader resource.ReadOnlyTransaction) ([]SignInMethod, error)

SignInMethods lists the sign-in methods the auth registers, in the login page's order, each with what an administrator chose for it. reader is the caller's transaction or the application's client: the rows are read as committed.

func (*Manager) SignInWays added in v0.5.0

func (m *Manager) SignInWays(ctx context.Context, txn resource.ReadOnlyTransaction, userID impulse.UUID) (ways []SignInWay, found bool, err error)

SignInWays lists how a person signs in: the password where they hold one, then each identity linked to them that can sign them in, by the session library's judgment (SessionAPI.SignsInThrough), with the registrations of the Auth's login page it comes through. It is what a page needs to offer the removal of a person's password only where RemovePassword would go through, a password held and an identity that counts, and to say what the removal leaves; an identity that signs nobody in is no way and is not listed. The password's hash, an identity's subject and everything else of either stay unread: the answer is whether, and through what. found is false where no user holds the id. It writes nothing, so it runs in any read.

The caller guards who may ask about whom: the generated management serves it to a person who may list the identities of the person asked about.

func (*Manager) SignUpRoles added in v0.5.0

func (m *Manager) SignUpRoles(ctx context.Context) ([]access.RoleInfo, error)

SignUpRoles lists the roles a person who signs up may be given, as the dialog that opens a method offers them: the roles held for the whole application, by name, the role file's and the custom ones, that the request's caller may give. A default role is given to every person who signs up, so a caller is offered the roles they could give a person directly and no other (mayGiveBySignUp); a call outside any request is the application's own and lists them all. The Super Administrator role is not among them: it is given by a super administrator, to a person they name.

func (*Manager) SignedIn added in v0.5.0

func (m *Manager) SignedIn(auth string, client resource.Client) session.SignedInHook

SignedIn answers the session library's hook for a sign-in that stands (session.Auth.SetSignedInHook): the person's assignments whose period has ended are removed, in a transaction of the hook's own on client, the application's database.

The session library calls the hook once the transaction that made the session has committed, and logs an error it answers while the session stands, so the removal can neither fail a sign-in nor undo one. A sign-in with nothing to clear costs one read and opens no transaction. A person whose every assignment has ended is refused at the sign-in as one who holds nothing, so nothing is cleared for them: the rows do nothing and go with the account.

func (*Manager) SignedUp added in v0.5.0

SignedUp answers the session library's hook for a sign-up through an open method (session.Auth.SetSignUpSeated): the default role the method's row names is buffered as a membership of the person for the whole application, in the transaction that makes the account. A role that cannot be given (it was deleted since the method was opened) fails the transaction, so no account is made holding nothing. The role is given by the application itself, outside any request's caller, and is held to the rule a role given by hand is, except that it is never the Super Administrator role, which the hook refuses whatever the row says.

auth names the Auth in the log line a given role leaves.

func (*Manager) TakeGroupRole added in v0.5.0

func (m *Manager) TakeGroupRole(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID, scope accesstypes.PolicyScope, role accesstypes.Role) error

TakeGroupRole buffers the removal of a role a group holds in the scope, in the caller's transaction, and has the permission engine told once the transaction has committed: every person in the group is served without the role at their next request, unless they hold it some other way. A role the group does not hold there is no error, and the role need not exist any more.

Taking a role from a group takes it from everyone in the group, so the removal is held to what a role's removal is: a request needs what taking the role from each of them directly needs (refuseTakingThrough), and a caller who is in the group does not take away the role that makes them the last administrator of a tenant (refuseLastAdministrator). A role whose period has ended gives nobody anything, and goes whoever asks.

func (*Manager) Tenant

func (m *Manager) Tenant(ctx context.Context) (*Tenant, error)

Tenant answers the rules for the tenant a method runs for: the one its request was checked in. A tenant's method acts for a request, so one run outside any request, in a transaction of the application's own, has no tenant and is an error: there the application runs the whole application's method and names the tenant itself.

func (*Manager) TenantAdministratorRoles added in v0.5.0

func (m *Manager) TenantAdministratorRoles() []accesstypes.Role

TenantAdministratorRoles answers the roles whose holders administer a tenant as the auth's permission engine names them (access.WithTenantAdministratorRoles): the names the sign-in rule and the session's reach into a tenant decide the administrators' way in by, so whatever lists who may enter a directory-only tenant reads these and no others. The generated identity client hands them to the tenant's list of its people.

func (*Manager) TenantRoles

func (m *Manager) TenantRoles(ctx context.Context, domain accesstypes.Domain) ([]access.RoleInfo, error)

TenantRoles lists the roles that exist in one tenant, by name: the tenant roles of the release's role file, and the custom roles held in the tenant and in every tenant (access.UserManager.Roles). They are the roles a membership of the tenant may name, so the list is what a role is picked from. Which of them a person may give is the role file's to say, in a condition on the grant of the method that gives one.

func (*Manager) UnlinkIdentity

func (m *Manager) UnlinkIdentity(ctx context.Context, txn resource.ReadWriteTransaction, identityID impulse.UUID) error

UnlinkIdentity buffers the removal of one identity, the link between a user and the identity a directory verified for them, in the caller's transaction: once it commits, a sign-in through that identity no longer reaches the user. The sessions established through it stand. A user who holds no password keeps an identity that can sign them in, since with none they could not sign in at all: the unlink is refused unless another identity linked to them is one the session library says a sign-in through is possible (SessionAPI.SignsInThrough), the judgment the removal of a password is held to (RemovePassword). The last identity that counts therefore stays while only ones that sign nobody in would remain, left from a sign-in method the Auth no longer offers or from a connection none of its registrations takes, and one of those goes from beside an identity that counts. A user who holds a password may lose every one. The rule holds for everyone, the last super administrator among them. A super administrator's identity is unlinked by a super administrator alone, since it is a way they sign in (requireSuperAdministratorFor).

The identities that rule reads are the committed ones, read in the transaction that unlinks: a second unlink of the same user's identities in one transaction does not see the first, as no read sees a buffered write. Unlink one identity of a user per transaction.

Shared rule: the session library's UnlinkIdentity, with its refusal (sessionstorage.ErrLastSignInMethod) and its judgment of the links that count.

func (*Manager) UnlockSignIn

func (m *Manager) UnlockSignIn(ctx context.Context, txn resource.ReadWriteTransaction, name string) error

UnlockSignIn buffers the removal of the count of failed sign-ins kept under a name, in the caller's transaction, and with it the lock the count earned: once it commits, the name may sign in again. The name is what was typed into the username field, whether or not a user holds it, and is keyed as the session library keys it (session.SignInAttemptName); a name with no count is no error.

Each instance of the application trusts what it remembers of a name for a few seconds, a lock included, so the lock is gone from every instance within that time of the commit, never at once. The locks the session library holds against a client's address and cookie are in each instance's memory alone and are not cleared: they throttle a client that kept trying, whatever name it tried.

func (*Manager) WithdrawInvitation

func (m *Manager) WithdrawInvitation(ctx context.Context, txn resource.ReadWriteTransaction, invitationID impulse.UUID) error

WithdrawInvitation buffers the withdrawal of an invitation that stands, in the caller's transaction: its link is then dead. It holds to invitations alone: the mail links table also keeps the links that verify an address and that start a sign-up, and one of those under the id is not found, as an invitation that does not exist is. An invitation that was accepted, withdrawn or has expired no longer stands and is not found either. Nor is an invitation that makes a tenant: it is withdrawn by its own method, under its own grant (WithdrawTenantInvitation), so the grant that withdraws an invitation into the application does not reach it.

Shared rule: the session library's RevokeInvitation, which consumes the live link of the id whatever its kind.

func (*Manager) WithdrawTenantInvitation added in v0.5.0

func (m *Manager) WithdrawTenantInvitation(ctx context.Context, txn resource.ReadWriteTransaction, invitationID impulse.UUID) error

WithdrawTenantInvitation buffers the withdrawal of an invitation that makes a tenant and still stands, in the caller's transaction: its link is then dead, and staff who want other details send another. It holds to these invitations alone: an invitation into a tenant that exists, a link of another kind, and one that no longer stands are not found.

type NameChange added in v0.5.0

type NameChange struct {
	Name *string
}

NameChange is the name a change writes on a user row: Name, nil for none.

type NewAccount

type NewAccount struct {
	Username string
	// Name is the person's name as people read it, nil for none: what pages show for
	// the person in place of the username. The person may change it themselves.
	Name *string
	// Email is the person's address, entered unverified; nil for none, and always nil
	// where the auth's usernames are the addresses.
	Email *string
	// Scope is where the roles are held, and Roles the roles: at least one.
	Scope accesstypes.PolicyScope
	Roles []accesstypes.Role
	// Password is a temporary password an operator chose, which the person changes
	// before anything else is served; nil for a person who signs in another way or
	// chooses their own from an invitation. PasswordRequired marks an auth where the
	// password is the only way in, so a person created without one could never sign
	// in. Both are for an auth with a password method alone.
	Password         *string
	PasswordRequired bool
}

NewAccount is a person to create: who they are, and the roles they hold from the start.

type NewTenant added in v0.5.0

type NewTenant struct {
	// Fields are the tenant record's fields as staff entered them: a JSON object keyed
	// by the record's Go field names, which the generated invitation method writes and
	// the generated maker reads. A field marked secret is never among them.
	Fields json.RawMessage
	// DirectoryOnly says the tenant is entered through its directory only. It is set
	// on the tenant where the record declares the switch, and only together with a
	// directory: the session library accepts such an invitation through an
	// organization's directory alone.
	DirectoryOnly bool
	// Directory is the organization's directory the accepting person signed in
	// through, which becomes the tenant's one directory; the zero value where they
	// came by password or with a personal account, and at the check a send makes.
	Directory signin.Directory
	// DefaultRole is the role a person from the tenant's directory starts with: the
	// directory row's default seat. Empty for none.
	DefaultRole accesstypes.Role
	// Source is what the change events of the tenant's rows name as their source: the
	// person who accepted and the invitation, since the write is made at a sign-in,
	// before any session stands.
	Source string
	// Caller is set at the check a send makes, and nil at an acceptance: the request's
	// caller, whose grants the record's create is held to (the Create grant on the
	// tenant record and on each field, with every condition), so a detail the sender
	// could not have written by creating the tenant is refused when the invitation is
	// sent. At an acceptance the write is the application's own.
	Caller *resource.Caller
}

NewTenant is a tenant to make from an invitation, as a TenantMaker takes it.

type NewUser

type NewUser struct {
	Username string
	// Name is the person's name as people read it, nil for none. It is written as
	// given: the manager has held it to the rule of a name (sessioninfo.CleanName).
	Name *string
	// Email is the address the person is reached at, nil for none. It is written
	// unverified.
	Email *string
}

NewUser is a user row as InsertUser writes it.

type Option

type Option func(*Manager)

Option configures a manager.

func WithAdministratorRoles

func WithAdministratorRoles(domain []accesstypes.Role) Option

WithAdministratorRoles names the roles whose holders administer a tenant: the domain roles a person holds in the tenant, or in every tenant. The rule on a person removing a role from themselves in a tenant reads them (RemoveRole): nobody gives up a tenant's administrator role nobody else would hold there. Without them a person removes no role from themselves in a tenant at all.

The application as a whole needs no such list: its last administrator is the last super administrator, the holder of the role the framework defines (accesstypes.SuperAdministrator), who is protected whoever asks. A person gives up any other role they hold in the global partition, since a super administrator gives it back.

func WithOneTenantPerPerson added in v0.5.0

func WithOneTenantPerPerson() Option

WithOneTenantPerPerson says a person belongs to one tenant: a role in a tenant is refused for a person who holds a role in another (AssignRole), and an invitation into a tenant for an address whose account another tenant holds (Invite). A refusal is a Conflict that carries the login refusal code sessioninfo.RefusedOtherTenant, which a sign-in that would seat the person in a second tenant ends on. A person who holds a role for the whole application or in every tenant is the application's own and is never refused; the last such role is not taken from a person who holds roles in more than one tenant (RemoveRole). Without the option a person may hold roles in any number of tenants.

func WithRoleGrants added in v0.5.0

func WithRoleGrants(grants RoleGrants) Option

WithRoleGrants hands the manager the answers of the role file's grants on the methods that give a role and take one away (RoleGrants), which the rules of a group read: a change to a group is held to what the role changes it makes need. The generated client passes its own; an application does not. A manager built without them refuses a change to a group that a request makes, since it could not judge it; a call outside any request is the application's own act and is not judged.

func WithSuperAdministratorMethods added in v0.5.0

func WithSuperAdministratorMethods(methods ...accesstypes.Resource) Option

WithSuperAdministratorMethods names the methods that give and take the auth's roles for the whole application, the ones the auth's generated management serves. A super administrator gives and takes any role whatever the role file grants, which the permission engine provides when it is built with the same methods (access.WithSuperAdministratorMethods). New holds the access library's engine to it and refuses one built without them, so an application that forgot the option does not start with a super administrator who can be locked out of the roles. The generated client passes the methods; an application does not.

func WithTenantMaker added in v0.5.0

func WithTenantMaker(maker TenantMaker) Option

WithTenantMaker hands the manager what makes a tenant from an accepted invitation (TenantMaker). The generated client of the auth a tenant is made through passes the one the application built with the generated New<Record>Maker; a manager without one sends no tenant invitation and accepts none.

func WithTenantWord added in v0.5.0

func WithTenantWord(word string) Option

WithTenantWord names what the application calls one tenant, as the middle of a sentence says it ("customer", "service district"): a refusal that speaks of a tenant says the application's word, the one its pages show. The generated client passes the tenant record's word. Without it, and for an empty word, the word is "tenant".

type PeriodStore added in v0.5.0

type PeriodStore interface {
	// SetMembershipPeriod buffers the period on a membership row, committed or written
	// earlier in this transaction.
	SetMembershipPeriod(ctx context.Context, txn resource.ReadWriteTransaction, key *access.MembershipKey, period accesstypes.Period) error
	// SetGroupMemberPeriod buffers the period on the row of a person's place in a group.
	SetGroupMemberPeriod(ctx context.Context, txn resource.ReadWriteTransaction, key *access.GroupMemberKey, period accesstypes.Period) error
	// SetGroupRolePeriod buffers the period on the row of a group's role.
	SetGroupRolePeriod(ctx context.Context, txn resource.ReadWriteTransaction, key *access.GroupRoleKey, period accesstypes.Period) error
	// UserPeriods reads every assignment of a person's own, each with its period: their
	// memberships, wherever each is held, and their places in groups. It reads through
	// any transaction, a read of its own among them, so a sign-in with nothing to clear
	// opens no transaction.
	UserPeriods(ctx context.Context, txn resource.ReadOnlyTransaction, userID impulse.UUID) (*UserPeriods, error)
	// GroupPeriods reads every member of a group and every role it holds, each with its
	// period.
	GroupPeriods(ctx context.Context, txn resource.ReadOnlyTransaction, groupID impulse.UUID) (*GroupPeriods, error)
	// EndedAssignments reads the person's own assignments whose period the database
	// says is over: the memberships and the places in groups whose end is at or before
	// the database's present, never the application server's. It reads through any
	// transaction, a read of its own among them, so a sign-in with nothing to clear
	// opens no transaction.
	EndedAssignments(ctx context.Context, txn resource.ReadOnlyTransaction, userID impulse.UUID) (memberships []access.MembershipKey, places []access.GroupMemberKey, err error)
	// RemoveEnded buffers the removal of memberships and places whose period ended,
	// each under the source EndedByItself in place of a person's act.
	RemoveEnded(ctx context.Context, txn resource.ReadWriteTransaction, memberships []access.MembershipKey, places []access.GroupMemberKey) error
}

PeriodStore is what the rules of an assignment's period need of one auth's tables, which the generated package of the auth implements over its own typed queries and patches. An implementation holds no rule: it reads and writes the two instants.

type RoleGrants added in v0.5.0

type RoleGrants interface {
	// MayGive reports whether the caller may give the person the role in the scope: the
	// grant of the method that gives a role admits it for that role and that person.
	MayGive(ctx context.Context, txn resource.ReadWriteTransaction, scope accesstypes.PolicyScope, userID impulse.UUID, role accesstypes.Role) (bool, error)
	// MayTake reports whether the caller may take the role the person holds in the scope
	// away: the grant of the method that takes a role away admits it for that role.
	MayTake(ctx context.Context, txn resource.ReadWriteTransaction, scope accesstypes.PolicyScope, userID impulse.UUID, role accesstypes.Role) (bool, error)
	// CouldGive reports whether the caller could give the role in the scope by hand, to
	// somebody: one of the methods a person gives a role with (the one that gives a
	// person a role, the create and the invitation that start a person with one, the
	// one that gives a group a role) does not refuse this caller the role. It is the
	// question of a list a role is picked from (Manager.RolesToGive), asked before
	// anybody is named: where what is left of a grant's condition reads the row a
	// method names (the person, the group), the role could be given to some of them,
	// and the answer is yes. It reads no row, and so takes no transaction.
	CouldGive(ctx context.Context, scope accesstypes.PolicyScope, role accesstypes.Role) (bool, error)
}

RoleGrants answers what the request's caller may do to a person's role, by the grants of the methods that give a role and take one away. The generated package of the auth implements it over the request's own check (resource.Caller.ExecuteGate): for a request made under a tenant, the grant of the tenant's method; for one made for the whole application, the grant of the whole application's. An implementation holds no rule of its own.

The default role of a sign-in method opened to sign-up is asked the same way (Manager.OpenSignUp), since opening the method gives the role to every person who signs up: for the whole application, of nobody in particular (the nil id, no account yet), and from the list of roles the dialog offers with no transaction (nil), which the whole application's method, naming no row, does not read.

type SessionAPI

type SessionAPI interface {
	// HashPassword hashes a password as the users table holds one; an empty password
	// is refused.
	HashPassword(password string) (string, error)
	// PrepareInvitation checks and makes an invitation without storing or mailing it:
	// the row to store, and the step that mails its link once the row is committed.
	// The token, the message and the sender stay in the session library.
	PrepareInvitation(ctx context.Context, req *session.InvitationRequest) (session.PreparedInvitation, error)
	// SignInMethods lists the sign-in methods the Auth registers, in the login page's
	// order: each with how wide it is and whether its directory gives the roles.
	SignInMethods() []session.RegisteredMethod
	// SignsInThrough names the sign-in registrations of the Auth's login page that an
	// identity of this method and connection can sign its person in through, and none
	// for an identity that signs nobody in: its method is no registration the page
	// offers any more, or no registration of the method takes its connection. It is the
	// one judgment of which links count as a means of sign-in, the session library's
	// own (session.AuthAPI.SignsInThrough): the removal of a password is refused, and
	// offered, by it.
	SignsInThrough(method sessioninfo.AuthMethod, connection string) []string
	// DirectoryName answers what the Auth's sign-in registrations call the directory an
	// identity of this method and connection came through: the name a registration that
	// takes the connection gives it, and the label of the button a person signs in to
	// it with, each "" where the registrations have none
	// (session.AuthAPI.DirectoryName). A sentence that names a directory to a person
	// says it by them, never by the connection.
	DirectoryName(method sessioninfo.AuthMethod, connection string) (name, label string)
}

SessionAPI is what the rules take from the session library's Auth, the one that signs the auth's people in: the API of the application's own Auth satisfies it (session.Auth.API). The password method's hasher is the Auth's, so a password written here is one the sign-in can check.

type SignInMethod added in v0.5.0

type SignInMethod struct {
	// Name is the name the method is registered under, and Label what the login page
	// shows for it.
	Name  string
	Label string
	// Admits is how wide the method is, as a sentence starts: "Anyone with an account
	// at lakeside.edu", "Anyone with a Google account". It is whom opening the method
	// to sign-up admits.
	Admits string
	// OpenSignUp says the method is open to sign-up; a method that is not is invite
	// only. DefaultRole is the role a new person is given through an open method, ""
	// for none.
	OpenSignUp  bool
	DefaultRole string
	// DirectoryGivesRoles marks a method whose directory gives the roles: the directory
	// decides who may sign in, and the method is neither opened nor made invite only.
	DirectoryGivesRoles bool
	// OwnRule marks a method whose registration carries an account rule of its own: the
	// application's code decides who may sign in through it, and the method is neither
	// opened nor made invite only.
	OwnRule bool
	// Says is the row's state as a sentence a person reads: what a person with no
	// invitation meets at this method.
	Says string
}

SignInMethod is one sign-in method the auth registers, with what an administrator chose for it, as the Sign-in page lists it.

type SignInMethodRow added in v0.5.0

type SignInMethodRow struct {
	// Name is the name the method is registered under.
	Name string
	// OpenSignUp says the method admits a person who holds no account and no invitation.
	OpenSignUp bool
	// OpenedFor is whom the method admitted when it was opened, as its registration's
	// audience spells itself (signin.Audience.Key), nil for a row that opens nothing.
	// The row opens the method for that audience and no other.
	OpenedFor *string
	// DefaultRole is the role such a person is given with their account, nil for none.
	DefaultRole *string
}

SignInMethodRow is a sign-in method's row of the sign-in methods table, as the rules read and write it.

type SignInWay added in v0.5.0

type SignInWay struct {
	// Password says the way is the person's password; every other way is an identity.
	Password bool
	// Identity is the linked identity, and Method and Connection the sign-in method
	// and the connection it came through, as the list of the person's identities
	// shows them. The password's are the zero id, the password method and no
	// connection.
	Identity   impulse.UUID
	Method     sessioninfo.AuthMethod
	Connection string
	// Registrations names the sign-in registrations of the Auth's login page the
	// identity can sign the person in through, in the page's order: one, except where
	// the Auth has two registrations of the identity's method and nothing of the
	// identity tells them apart. The password's is the password method's name alone.
	Registrations []string
}

SignInWay is one way a person signs in, as an administrator's page reads it: the person's password, or an identity linked to them that can sign them in. It carries what the list of the person's identities shows of the identity and no more: never a subject, an address or a hash.

func (*SignInWay) Key added in v0.5.0

func (w *SignInWay) Key() string

Key names the way among the ways one person signs in: PasswordWay for the password, and the identity's id for an identity.

type SignUp added in v0.5.0

type SignUp struct {
	// Method is the name the method is registered under.
	Method string
	// DefaultRole is the role each person who signs up is given, a role held for the
	// whole application. An application without tenants names one; an application with
	// tenants names none.
	DefaultRole accesstypes.Role
	// CreatesTenant marks an application with tenants: a person who signs up holds no
	// role, and creates a tenant of their own, which they administer.
	CreatesTenant bool
}

SignUp is what opening a sign-in method to sign-up asks for.

type Store

type Store interface {
	// InsertUser buffers a new user and answers the id the row is created under.
	InsertUser(ctx context.Context, txn resource.ReadWriteTransaction, user *NewUser) (impulse.UUID, error)
	// UpdateUser buffers a change to a user: every field of change that is set.
	UpdateUser(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, change *UserChange) error
	// SetPassword buffers a user's password hash, as the session library's hasher
	// rendered it, and whether the person must change the password before anything
	// else is served. An auth with no password method has no such write.
	SetPassword(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, hash string, changeRequired bool) error
	// RemovePassword buffers the removal of a user's password, and with it the mark that
	// the person must change it. An auth with no password method has no such write.
	RemovePassword(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
	// ClearAttempts buffers the removal of the count of failed sign-ins kept under a
	// name (session.SignInAttemptName); a name with no count is no error.
	ClearAttempts(ctx context.Context, txn resource.ReadWriteTransaction, name string) error
	// UserHasPassword reads whether a user holds a password; found is false where no
	// user holds the id. The hash itself is read by nothing. It writes nothing, so a
	// read outside a write asks it too (SignInWays).
	UserHasPassword(ctx context.Context, txn resource.ReadOnlyTransaction, id impulse.UUID) (has, found bool, err error)

	// IdentityUser reads the user an identity links to; found is false where no
	// identity holds the id. An auth that keeps no identities finds none.
	IdentityUser(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (userID impulse.UUID, found bool, err error)
	// Identities lists the identities linked to a user, each with the sign-in method
	// and the connection it came through, which say whether it can still sign the
	// person in. It writes nothing, so a read outside a write asks it too (SignInWays).
	Identities(ctx context.Context, txn resource.ReadOnlyTransaction, userID impulse.UUID) ([]Link, error)
	// DeleteIdentity buffers the removal of an identity.
	DeleteIdentity(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error

	// Token reads a bearer token; found is false where no token holds the id. An auth
	// that issues no tokens finds none.
	Token(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (token *Token, found bool, err error)
	// FamilyTokens lists the tokens of a family that are not revoked.
	FamilyTokens(ctx context.Context, txn resource.ReadWriteTransaction, family impulse.UUID) ([]impulse.UUID, error)
	// RevokeToken buffers the revocation of one token, with the reason.
	RevokeToken(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, reason string) error

	// Username reads a user's username; found is false where no user holds the id.
	Username(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (username string, found bool, err error)
	// UserDisabled reads whether a user is disabled; found is false where no user holds
	// the id. The rule on the last super administrator reads it: a holder of the role
	// who cannot sign in is nobody's way back in.
	UserDisabled(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (disabled, found bool, err error)
	// UserID reads the id of the user who holds a username, compared as the auth
	// compares names at a sign-in; found is false where none does. It is how a new
	// name is found taken. The permission store names a person by the id of their
	// account; the username stays on what carries it for reading, the person's live
	// sessions and the impersonation records they hold as actor, which a rename
	// rewrites (RenameUser).
	UserID(ctx context.Context, txn resource.ReadWriteTransaction, username string) (id impulse.UUID, found bool, err error)
	// UserByVerifiedEmail answers the id of the user who has confirmed the address,
	// compared as the table's unique index compares addresses; found is false when no
	// user holds it, and when the one who does has not confirmed it.
	UserByVerifiedEmail(ctx context.Context, txn resource.ReadWriteTransaction, email string) (userID impulse.UUID, found bool, err error)
	// DeleteUser buffers the removal of a user row.
	DeleteUser(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error

	// LiveSessions lists the sessions of the user that have not ended.
	LiveSessions(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) ([]impulse.UUID, error)
	// SessionExpired reads whether a session has ended; found is false where no
	// session holds the id.
	SessionExpired(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (expired, found bool, err error)
	// EndSession buffers the end of one session.
	EndSession(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
	// RenameSession buffers a new username on one session.
	RenameSession(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID, username string) error

	// Impersonation reads the impersonation record of a session: found is false where
	// the session has none, and live says a record that is found has not ended. An
	// auth that keeps no such records finds none.
	Impersonation(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID) (live, found bool, err error)
	// ImpersonationsHeldBy lists the sessions whose record has not ended and names the
	// username as its actor, a person of this auth (the record's realm is empty). An
	// auth that keeps no such records answers none.
	ImpersonationsHeldBy(ctx context.Context, txn resource.ReadWriteTransaction, username string) ([]HeldImpersonation, error)
	// RenameImpersonationActor buffers a new actor's name on a session's record.
	RenameImpersonationActor(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID, username string) error
	// EndImpersonation buffers the end of a session's impersonation record, with the
	// reason it ended.
	EndImpersonation(ctx context.Context, txn resource.ReadWriteTransaction, sessionID impulse.UUID, reason string) error

	// HasRole reports whether the roles table holds the row of a custom role, read in
	// the transaction.
	HasRole(ctx context.Context, txn resource.ReadWriteTransaction, key *access.RoleKey) (bool, error)
	// HasMembership reports whether the membership row is committed.
	HasMembership(ctx context.Context, txn resource.ReadWriteTransaction, key *access.MembershipKey) (bool, error)
	// Memberships lists every membership the user holds, wherever it is held. A
	// membership names its person by the id of their account (User).
	Memberships(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) ([]access.MembershipKey, error)
	// RoleHolders lists who holds the role where the key says it is held, each by the
	// id of their account.
	RoleHolders(ctx context.Context, txn resource.ReadWriteTransaction, key *access.RoleKey) ([]accesstypes.User, error)
	// InsertMembership buffers a membership row unless the membership is there already,
	// committed or written earlier in this transaction, and reports whether it did. A
	// membership that is there is left exactly as it is, the time it was given included.
	InsertMembership(ctx context.Context, txn resource.ReadWriteTransaction, key *access.MembershipKey) (inserted bool, err error)
	// DeleteMembership buffers the removal of a membership row.
	DeleteMembership(ctx context.Context, txn resource.ReadWriteTransaction, key *access.MembershipKey) error
	// TenantMemberships lists every membership held in one tenant, whoever holds it:
	// the rows of the memberships table under the tenant's own scope. A membership
	// held in every tenant is no row of one tenant and is not listed.
	TenantMemberships(ctx context.Context, txn resource.ReadWriteTransaction, domain accesstypes.Domain) ([]access.MembershipKey, error)
	// DeleteTenantRoles buffers the removal of every custom role made in one tenant
	// with its grants: the rows of the roles table and of the grants table under the
	// tenant's own scope. It answers how many roles go.
	DeleteTenantRoles(ctx context.Context, txn resource.ReadWriteTransaction, domain accesstypes.Domain) (roles int, err error)

	// InsertInvitation buffers the mail links row of a prepared invitation, as the
	// session library says one is written (session.InvitationRow).
	InsertInvitation(ctx context.Context, txn resource.ReadWriteTransaction, row *session.InvitationRow) error
	// MailLink reads one link the auth mailed; found is false where no link holds the
	// id.
	MailLink(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) (link *MailLink, found bool, err error)
	// ConsumeMailLink buffers the consumption of one link: it is then dead.
	ConsumeMailLink(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error
	// TenantInvitations lists the invitations into one tenant that are not consumed:
	// neither accepted nor withdrawn. An auth that mails no links answers none.
	TenantInvitations(ctx context.Context, txn resource.ReadWriteTransaction, domain accesstypes.Domain) ([]impulse.UUID, error)
	// InvitedTenants lists the invitations that make a tenant and are not consumed,
	// neither accepted nor withdrawn, oldest first, each with the document its
	// NewTenant column holds. reader is the caller's transaction or the application's
	// client. An auth that mails no links answers none.
	InvitedTenants(ctx context.Context, reader resource.ReadOnlyTransaction) ([]InvitedTenantRow, error)

	// SignInMethodRows lists the rows of the sign-in methods table: what an
	// administrator chose for each method that has a row. reader is the caller's
	// transaction or the application's client. A schema that holds no such table
	// answers none, which is every method invite only.
	SignInMethodRows(ctx context.Context, reader resource.ReadOnlyTransaction) ([]SignInMethodRow, error)
	// SetSignInMethod buffers the row of the method it names, written whole: created
	// where the method has none, replaced where it has one. The write keeps who made
	// it and when (the table's change events).
	SetSignInMethod(ctx context.Context, txn resource.ReadWriteTransaction, row *SignInMethodRow) error

	// TrustedDevices lists the browsers the user asked to be remembered after the
	// second factor that are not revoked. An auth that keeps none answers none.
	TrustedDevices(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID) ([]impulse.UUID, error)
	// RevokeTrustedDevice buffers the revocation of one remembered browser.
	RevokeTrustedDevice(ctx context.Context, txn resource.ReadWriteTransaction, id impulse.UUID) error

	// GroupStore is the auth's groups of people, their members and the roles they hold
	// (groups.go).
	GroupStore
	// PeriodStore is the period of an assignment: a person's role, a person's place in
	// a group and a group's role (periods.go).
	PeriodStore
}

Store is what the rules need of one auth's tables: single reads and single buffered writes, which the generated package of the auth implements over its own typed queries and patches. An implementation holds no rule: it maps the values it is given onto the auth's columns and answers what it read.

type Tenant

type Tenant struct {
	// contains filtered or unexported fields
}

Tenant is the rules as the methods of one tenant apply them.

func (*Tenant) AddGroupMember added in v0.5.0

func (t *Tenant) AddGroupMember(ctx context.Context, txn resource.ReadWriteTransaction, groupID, userID impulse.UUID) error

AddGroupMember buffers a person's place in a group of the tenant, with no period (see AddGroupMemberFor).

func (*Tenant) AddGroupMemberFor added in v0.5.0

func (t *Tenant) AddGroupMemberFor(ctx context.Context, txn resource.ReadWriteTransaction, groupID, userID impulse.UUID, period accesstypes.Period) error

AddGroupMemberFor buffers a person's place in a group of the tenant, for the period (see Manager.AddGroupMemberFor). The person is one the tenant already has: a row of its own list of the auth's people, held here as the generated frame holds the person of a role given in the tenant, since the frame of this method locates the group. An account from outside the tenant is not found there (requireTenantPerson), and is put into a tenant's group by whoever manages the whole application's people, through the whole application's method: a tenant's group holds any account, and a tenant's administrator puts in the ones the tenant has.

func (*Tenant) AssignRole

func (t *Tenant) AssignRole(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, role accesstypes.Role) error

AssignRole buffers the membership that gives a person a role in the tenant (see Manager.AssignRole, whose rule on the role it is held to). The person is named by the id of their account.

func (*Tenant) AssignRoleFor added in v0.5.0

func (t *Tenant) AssignRoleFor(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, role accesstypes.Role, period accesstypes.Period) error

AssignRoleFor is Tenant.AssignRole with the period the role is held for (see Manager.AssignRoleFor).

func (*Tenant) CreateGroup added in v0.5.0

func (t *Tenant) CreateGroup(ctx context.Context, txn resource.ReadWriteTransaction, name, description string) (impulse.UUID, error)

CreateGroup buffers a new group kept in the tenant (see Manager.CreateGroup).

func (*Tenant) CreateUser

func (t *Tenant) CreateUser(ctx context.Context, txn resource.ReadWriteTransaction, account *NewAccount) (impulse.UUID, error)

CreateUser buffers a new user who holds the roles in the tenant (see Manager.CreateUser). The roles are held in the tenant whatever scope the account names.

func (*Tenant) DeleteGroup added in v0.5.0

func (t *Tenant) DeleteGroup(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID) error

DeleteGroup buffers the removal of a group of the tenant, once it is emptied (see Manager.DeleteGroup).

func (*Tenant) DescribeGroup added in v0.5.0

func (t *Tenant) DescribeGroup(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID, description string) error

DescribeGroup buffers a new description on a group of the tenant (see Manager.DescribeGroup).

func (*Tenant) Domain

func (t *Tenant) Domain() accesstypes.Domain

Domain is the tenant.

func (*Tenant) GiveGroupRole added in v0.5.0

func (t *Tenant) GiveGroupRole(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID, role accesstypes.Role) error

GiveGroupRole buffers a role a group of the tenant holds in the tenant, the one place a tenant's group holds a role (see Manager.GiveGroupRole).

func (*Tenant) GiveGroupRoleFor added in v0.5.0

func (t *Tenant) GiveGroupRoleFor(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID, role accesstypes.Role, period accesstypes.Period) error

GiveGroupRoleFor is Tenant.GiveGroupRole with the period the group holds the role for (see Manager.GiveGroupRoleFor).

func (*Tenant) Invite

func (t *Tenant) Invite(ctx context.Context, txn resource.ReadWriteTransaction, inv *Invitation, sent func(sent bool)) (impulse.UUID, error)

Invite buffers an invitation into the tenant and has its link mailed once the transaction has committed (see Manager.Invite). The roles are held in the tenant whatever tenant the invitation names.

func (*Tenant) RemoveGroupMember added in v0.5.0

func (t *Tenant) RemoveGroupMember(ctx context.Context, txn resource.ReadWriteTransaction, groupID, userID impulse.UUID) error

RemoveGroupMember buffers the removal of a person from a group of the tenant (see Manager.RemoveGroupMember).

func (*Tenant) RemoveRole

func (t *Tenant) RemoveRole(ctx context.Context, txn resource.ReadWriteTransaction, userID impulse.UUID, role accesstypes.Role) error

RemoveRole buffers the removal of a role a person holds in the tenant, under the rules of Manager.RemoveRole: the last administrator of the tenant keeps the role, and a person left with no role anywhere is deleted. The person's id and the role are the key of the row in the tenant's list of the roles held there.

The role goes where the tenant holds a membership of its own for it. A role the person holds in every tenant alone is a row of the tenant's list too, and is not the tenant's to take: it is refused as a Conflict, and goes for the whole application or not at all. A role the person holds neither way is no error.

func (*Tenant) TakeGroupRole added in v0.5.0

func (t *Tenant) TakeGroupRole(ctx context.Context, txn resource.ReadWriteTransaction, groupID impulse.UUID, role accesstypes.Role) error

TakeGroupRole buffers the removal of a role a group of the tenant holds in the tenant (see Manager.TakeGroupRole).

type TenantInvitation added in v0.5.0

type TenantInvitation struct {
	// Email is the address the invitation is mailed to.
	Email string
	// Name is the name the sender gives the person, nil for none.
	Name *string
	// TenantName is what people will call the tenant. The invitation page shows it to
	// the invited person before they sign in; nothing else of the tenant is shown there.
	TenantName string
	// Fields are the tenant record's fields as staff entered them (NewTenant.Fields).
	Fields json.RawMessage
	// DirectoryOnly says the tenant is entered through its directory only, so the
	// invitation is accepted through an organization's directory alone.
	DirectoryOnly bool
	// DefaultRole is the role a person from the tenant's directory starts with, nil for
	// none: the tenant then admits its directory's people by invitation.
	DefaultRole *string
}

TenantInvitation is an invitation that makes a tenant, to send.

type TenantMaker added in v0.5.0

type TenantMaker interface {
	// Make buffers the tenant's row in the caller's transaction, by the rules the
	// record's create applies, and answers the tenant's id as the domain of the roles
	// held in it. With a directory it buffers the tenant's directory row too, with the
	// default role, held to the rules of a tenant's directory: a directory another
	// tenant has is refused as a sign-in is (sessioninfo.RefusedOrganizationHasTenant),
	// and nothing is written. What the instance owes after the commit (its roster
	// rereading the tenants, the word to the other instances) it registers on the
	// transaction (resource.AfterCommit).
	Make(ctx context.Context, txn resource.ReadWriteTransaction, tenant *NewTenant) (accesstypes.Domain, error)
	// SeatsDefaultRole reports whether the tenant's directory keeps a default role: the
	// directories record carries the column. An invitation names a starting role only
	// where it does.
	SeatsDefaultRole() bool
	// DeclaresDirectoryOnly reports whether the tenant record declares the
	// directory-only switch. An invitation says directory only where it does.
	DeclaresDirectoryOnly() bool
}

TenantMaker makes a tenant from an invitation's details. The generator writes one over the tenant record (New<Record>Maker in the handler package), and an application writes none.

type Token

type Token struct {
	// FamilyID is the device authorization the token belongs to, nil for a token that
	// stands alone.
	FamilyID *impulse.UUID
	// ExpiresAt is when the token stops being accepted, and Revoked whether it was
	// revoked before that.
	ExpiresAt time.Time
	Revoked   bool
}

Token is a bearer token as the rules read it.

type UserChange

type UserChange struct {
	Username               *string
	Disabled               *bool
	PasswordChangeRequired *bool
	// Email, where set, replaces the address the row holds. An address written here was
	// entered by hand, so the row is left unverified: the time the address it held was
	// verified goes with it.
	Email *EmailChange
	// Name, where set, replaces the name the row holds.
	Name *NameChange
}

UserChange is a change to a user row: a nil field is left as it is.

type UserPeriods added in v0.5.0

type UserPeriods struct {
	Memberships map[access.MembershipKey]accesstypes.Period
	Places      map[access.GroupMemberKey]accesstypes.Period
}

UserPeriods is the periods of a person's own assignments: an assignment with no period is there with the zero Period.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL