Documentation
¶
Overview ¶
Package signin is the contract between the Auth session and a sign-in method.
The Auth session (the core) owns sessions, users, identities, the pending flow and the middleware. A sign-in method is a package that knows one way to establish who the person is: a password form in the core itself, or a redirect to an identity provider such as Microsoft Entra ID, Google Workspace or WorkOS. An external method registers on the core with Register and hands it a Method: how to begin the round trip to the provider, how to complete it into a verified identity, and how to synchronize the user's roles when the provider asserts them. The core builds the HTTP handlers, runs resolution, the sign-in policy and the session the same way for every method, and returns the handlers to the method.
The package also holds the vocabulary of a sign-in's outcomes, which the application's hooks speak: a custom AccountRule's Resolution, the sign-in policy's Decision and the causes of a refusal.
A method package imports this package and never the core.
Index ¶
- Constants
- Variables
- func AddressDomain(email string) string
- func IdentitiesOfKey(key string) (identities []string, ok bool)
- func LoginHint(r *http.Request) (string, error)
- func RoleNames(names []string) []string
- func SelectAccount(r *http.Request) (bool, error)
- type AccountRule
- type Advertisement
- type Audience
- type Core
- type Decision
- type DeclarationReader
- type DeclaredDirectory
- type Directory
- type DirectoryReader
- type DirectorySeat
- type DisabledRoleSyncConfig
- type Handlers
- type IdentityOutcome
- type Issuers
- type Kind
- type LoginOptions
- type Method
- type NewUser
- type PendingSignInError
- type Policy
- type PolicyOutcome
- type Registration
- type Resolution
- func Confirm(userID impulse.UUID, opts ...ResolutionOption) *Resolution
- func Link(userID impulse.UUID, trusted bool, opts ...ResolutionOption) *Resolution
- func Provision(user *NewUser, ...) *Resolution
- func Reject(code sessioninfo.LoginRefusalCode) *Resolution
- func Standard(opts ...ResolutionOption) *Resolution
- func (r *Resolution) NewUser() *NewUser
- func (r *Resolution) OnProvisioned() func(ctx context.Context, userID impulse.UUID) error
- func (r *Resolution) Outcome() IdentityOutcome
- func (r *Resolution) Refusal() sessioninfo.LoginRefusalCode
- func (r *Resolution) Seats() []DirectorySeat
- func (r *Resolution) Tenant() string
- func (r *Resolution) Trusted() bool
- func (r *Resolution) UserID() impulse.UUID
- type ResolutionOption
- type RoleReconciler
- type RoleSyncConfig
- type StateCookies
- type SuperAdministratorCheck
- type TenantDeclaration
- type TenantPolicyOption
- type UserRoleManager
- type Verified
Constants ¶
const ( // GoogleAnyAccountConnection is the connection of a Google account that is in none // of a registration's named Workspaces and was admitted as any Google account: the // provider itself (google.AnyAccountConnection). GoogleAnyAccountConnection = "accounts.google.com" // MicrosoftPersonalAccountsConnection is the connection of a Microsoft personal // account (outlook.com, hotmail.com, Xbox): the one tenant id every personal // account's token carries (azure.ConsumerTenantID). MicrosoftPersonalAccountsConnection = "9188040d-6c67-4c5b-b112-36a304b66dad" )
The two connections that stand for everyone who is in no organization. An identity that came through one of them was vouched for by the provider alone, so the connection names no organization: every such account in the world carries the same value. Neither is a directory a tenant can take as its own (Directory.Organization).
Variables ¶
var ( // ErrIdentityRejected is the cause when the account rule returned RejectIdentity // (Reject). The code is the resolution's, or sessioninfo.RefusedIdentityRejected // when that is empty. ErrIdentityRejected = errors.New("signin: the account rule rejected the identity") // ErrLinkRequiresConfirmation is the cause when the account rule returned // LinkIdentity (Link) for a user that has a password, without trusted. The code is // sessioninfo.RefusedIdentityRejected. The rule should return Confirm instead. ErrLinkRequiresConfirmation = errors.New( "signin: an identity can't be linked to a user that has a password without confirmation (or a trusted link)") // ErrLinkCrossConnection is the cause when the account rule returned LinkIdentity // (Link) without trusted, or the standard rule matched a pre-created user, for a user // that has no password and already signs in through another connection. No // confirmation can be asked of such a user, so the rule's evidence is the only // check, and a custom rule must say so with trusted, or reject. The code is // sessioninfo.RefusedIdentityRejected. ErrLinkCrossConnection = errors.New( "signin: an identity from another connection can't be linked to a user without a password unless the link is trusted") // ErrLinkSecondIdentity is the cause when the standard rule matched a pre-created // user by the sign-in name the identity asserts, for a user that has no password, // already signs in through an identity on the same connection, and does not hold, // verified, the address the method verified for the identity. A name proves // nothing, and no confirmation can be asked of such a user, so the standard rule's // match on a name is linked as a user's first identity and never as a second one: // a user given a password confirms the link with it, a registration's own rule // links it on its own evidence, or the application links it itself. The code is // sessioninfo.RefusedIdentityRejected. ErrLinkSecondIdentity = errors.New( "signin: an identity the application has not seen can't be linked on its sign-in name to a user who already signs in through another identity") // ErrEmailHeld is the cause when an account rule provisioned a new user for an // identity whose verified address another user already holds verified: that user // is the person, and the standard rule matches the person by the address before // it provisions, so the sign-in is refused rather than a second user made for one // person. The code is sessioninfo.RefusedIdentityRejected. ErrEmailHeld = errors.New("signin: the identity's verified email address belongs to another user") // ErrGuestAccount is the cause when the standard rule refused a guest of the // directory (Identity.Guest). The code is sessioninfo.RefusedGuestAccount. ErrGuestAccount = errors.New("signin: the identity is a guest of its directory, not a member") // ErrNoRoles is the cause when the standard rule refused a token that asserts // no application role for a method that synchronizes roles, before any row was // written. The code is sessioninfo.RefusedNoRoles. ErrNoRoles = errors.New("signin: the token asserts no application role") // ErrNoSignInName is the cause when the standard rule found no sign-in name // on the identity to use as the username. The code is sessioninfo.RefusedNoEmail. ErrNoSignInName = errors.New("signin: the identity carries no sign-in name to use as the username") // ErrNotInvited is the cause when a sign-in method that is invite only met a // person who holds no account and carried no invitation: nothing is written. A // method is invite only until an administrator opens it to sign-up. The code is // sessioninfo.RefusedNotInvited. ErrNotInvited = errors.New("signin: the sign-in method is invite only, and the person holds no account and no invitation") // ErrInvitationOnly is the cause when the standard rule refused a stranger // from a directory a tenant declares with no default seat: the tenant admits its // people by invitation, the sign-in carried none, and nothing is provisioned. The // code is sessioninfo.RefusedInvitationOnly. ErrInvitationOnly = errors.New("signin: the tenant that declares the directory admits its people by invitation only") // ErrInvitationExpired is the cause when the invitation a sign-in carried, which // alone admitted the person through a method that is invite only, had expired or been // used by the time the sign-in accepted it; nothing is provisioned. The code is // sessioninfo.RefusedInvitationExpired. ErrInvitationExpired = errors.New("signin: the invitation has expired or was already used") // ErrInvitationAddress is the cause when a sign-in or an acceptance carried an // invitation mailed to another address: an invitation is accepted only by the // account it was sent to (an account with no address, by the link), so the sign-in // or acceptance is refused and the invitation left standing. The code is // sessioninfo.RefusedInvitationAddress. ErrInvitationAddress = errors.New("signin: the directory's address is not the one the invitation was mailed to") // ErrOrganizationAccountRequired is the cause when a sign-in or an acceptance // carried an invitation that makes a tenant entered through its directory only, and // the person did not come through an organization's directory (a password, a // personal account): nothing is written and the invitation stands. The code is // sessioninfo.RefusedOrganizationAccountRequired. ErrOrganizationAccountRequired = errors.New("signin: the invitation makes a tenant entered through its directory only, and the sign-in came through no organization's directory") // ErrSignInDenied is the cause when the sign-in policy returned DenySignIn or no // decision. The code is the decision's, or sessioninfo.RefusedByPolicy. A refusal // of the tenant policy carries its own cause beside it. ErrSignInDenied = errors.New("signin: the sign-in policy denied the sign-in") // ErrNoTenant is the cause when the tenant policy refused a person who is a member // of no tenant. The code is sessioninfo.RefusedNoTenant. ErrNoTenant = errors.New("signin: the person is a member of no tenant") // ErrConnectionNotInTenant is the cause when the tenant policy refused a sign-in // through a directory because every tenant of the person admits its people through // its own directory only, and none of them has the directory the sign-in came // through. The code is sessioninfo.RefusedConnectionNotInTenant. ErrConnectionNotInTenant = errors.New("signin: every tenant of the person admits its people through its own directory only, and the sign-in came through another directory") // ErrDirectoryOnly is the cause when the tenant policy refused a sign-in that is not // through a directory because every tenant of the person admits its people through // its own directory only. The code is sessioninfo.RefusedDirectoryOnly. ErrDirectoryOnly = errors.New("signin: every tenant of the person admits its people through its own directory only") // ErrUserDisabled is the cause when the sign-in resolved to a disabled user. // The code is sessioninfo.RefusedUserDisabled. ErrUserDisabled = errors.New("signin: the user is disabled") )
The causes of a refused sign-in, for errors.Is. A refused sign-in is also a sessioninfo.LoginRefusal, which carries the code the login page receives, and an Unauthorized client message.
Functions ¶
func AddressDomain ¶
AddressDomain is the domain of an email address, lowercased: what follows its last @, or "" when it has none. A method's AdmitsAddress judges an address by it.
func IdentitiesOfKey ¶ added in v0.5.0
IdentitiesOfKey reads back the identities a key was made of, in the key's order. ok is false for text that is no key as Key writes it, which names no audience: an earlier form of the key among them.
func LoginHint ¶
LoginHint reads ?login_hint= from a login request: the account the provider is asked to pick, or whatever else the provider reads from its login hint, or "" when the login page gave none. It is a hint and is never read back; the identity comes from the verified token. A hint longer than an email address can be, or carrying spaces or control characters, is a login page's mistake and is refused with 400.
Types ¶
type AccountRule ¶
type AccountRule[Tx any] func(ctx context.Context, tx Tx, req *sessioninfo.NewSessionRequest) (*Resolution, error)
AccountRule is an application's own rule for an external identity's first sign-in: an identity that is not linked to any user yet is given to it, and it answers who the person is with Reject, Link, Provision or Confirm, or leaves the decision to the library's standard rule with Standard, after checks of its own. It is optional: every external method takes one at its registration, typed to the method's identity (azure.AccountRule, google.AccountRule), and hands the core this form over the sign-in request. It runs in the first of a sign-in's two transactions, which commits unless an error is returned, so a rejection keeps the rule's own writes; see "Storage and schema" in the README. Tx is the storage's transaction type: pgx.Tx on PostgreSQL, *spanner.ReadWriteTransaction on Spanner. Spanner may retry the transaction, so the rule must not have side effects outside it. A linked identity never reaches it.
The standard rule is the library's, applied inside the same transaction when the registration has no AccountRule or its AccountRule answers Standard. It refuses a guest of the directory (guest_account) and, when the method synchronizes roles, a token asserting no application role (no_roles), both before any row is written; the identity's sign-in name (Identity.SignInName: the user principal name on Entra, the verified email on Google) is the username, and an identity without one is refused (no_email). A pre-created user under that name, matched without regard to case, or one who holds the identity's address verified when the method verified it (Identity.EmailVerified), is linked: after a password confirmation when the user has a password, outright when the user has none and signs in through no other connection yet. A person no user was created for is decided by what an administrator chose for the method in the running application, its row of the sign-in methods table, read in this transaction: a method opened to sign-up admits them and makes their account, with the role the row names; a method with no row is invite only, where the invitation the sign-in carries is the account, and without one the person is refused (not_invited) and nothing is written. A method whose directory writes the roles has no such choice: the directory says who holds a role, and a person it gives one is admitted. In an application with tenants, the tenant whose directory the identity came through decides before the method does (signin.DirectoryReader).
A user created ahead is found by the sign-in name, and nothing else ties the two. In an application whose tenants have directories (the Auth's directory admission), a user who has no password and has never signed in is linked on the name only when something vouches for the link: the sign-in came through the directory of the one tenant the user belongs to, holding a role there and nothing anywhere else, or it carries the user's own invitation. Any other sign-in under the name is refused as a person no user was created for is, since a directory asserts the names it likes. A registration that declares its provider's names the application's own (Registration.SeededUsers) links such a user on the name alone. A user with no password who already signs in through an identity is never linked a second one on the name (ErrLinkSecondIdentity): a person may hold an account under another person's sign-in name, and such a user has no password to confirm with. A user who holds, verified, the address the method verified for the identity is the person, and is linked on a connection they already sign in through.
type Advertisement ¶
type Advertisement struct {
// Name is the name the method was registered under on the Auth: "password", or the
// application's name for an external registration ("google", "lakeside-entra").
Name string `json:"name"`
// Method is the method behind the registration (password, azure, google, workos,
// oidc).
Method sessioninfo.AuthMethod `json:"method"`
// Kind is how the method starts: a form or a redirect.
Kind Kind `json:"kind"`
// Label is what the page shows for the method, the application's wording.
Label string `json:"label"`
// Path is where the application mounted the method's Login handler: the form posts
// to it, the redirect goes to it.
Path string `json:"path"`
}
Advertisement is one registered sign-in method as the Auth lists it to the login page (Auth.Methods). The page renders from the list alone: a method that is not registered is not listed and has no button, so the browser bundle is the same in every environment.
type Audience ¶ added in v0.5.0
type Audience struct {
// Organizations are the organizations the method is limited to, each as a person
// would name it: a Google Workspace by its domain, a Microsoft Entra tenant by the
// application's name for it.
Organizations []string
// Accounts is what an account the method admits outside those organizations is
// called, with its article ("a Google account", "a Microsoft work or school
// account", "an email address"); "" for a method limited to its organizations.
Accounts string
// Identities is whom the method admits as its provider identifies them, which is
// what Key spells: an entry for each organization the method admits (a Microsoft
// Entra tenant by its tenant id, a Google Workspace by its domain, another provider
// by its issuer) and one for each kind of account it admits outside them, each
// qualified by its kind so that no two kinds read alike. A name is the
// application's to give, and a second organization can be given the first one's;
// an identity is one organization's alone, so two registrations that admit
// different people never share their identities, whatever they are called. The
// library's own methods give them. A method that gives none is compared by the
// names it gives (Organizations, Accounts), which then must be its organizations'
// alone.
Identities []string
}
Audience is how wide a sign-in method is: the people its provider could sign in, which the method's registration fixes in code. A method limited to organizations it names admits their people alone; a method open to any organization, or to personal accounts, admits anyone who has such an account. It is what opening the method to sign-up admits, so the page where an administrator opens a method says it in words (Words), and the warning the administrator confirms says it too.
The words are for people. What two audiences are compared by is Identities, which names each organization by what is that organization's alone.
func (Audience) Key ¶ added in v0.5.0
Key is the audience in a form that compares exactly: two registrations admit the same people exactly when their keys are equal, whatever order their organizations were listed in and whatever they are called. It is what a sign-in method's row keeps of the audience the method was opened to sign-up for, so a registration that code changes afterwards is not open on the strength of a confirmation given for other people. The key spells the identities (Identities), never the names: a second organization listed under the name of the first changes the key, and the same organization given another name does not.
A key reads back as its identities (IdentitiesOfKey). Text of any other form is no key and equals none, so a row that kept its audience in an earlier form, by its names, opens nothing.
func (Audience) Limited ¶ added in v0.5.0
Limited reports whether the method admits the people of the organizations it names and nobody else.
func (Audience) OneOrganization ¶ added in v0.5.0
OneOrganization reports whether the method admits the people of exactly one organization and nobody else: the width at which a name a sign-in presents can have come from one directory alone, which the rule on the first link of a deployment's seeded account asks. It counts the organizations as the registration listed them, never as Key spells them: Key writes each identity once, and each name once for a method that gives no identities, where two organizations given one name would read as one. A Google Workspace named with several domains is listed by each domain and reads as several, which errs toward the wider answer.
func (Audience) Words ¶ added in v0.5.0
Words says whom the method admits, as the middle of a sentence: "anyone with an account at acme.example" for a method limited to its organizations, "anyone with a Google account" for one that is not. A method that says nothing about itself admits "anyone who can sign in through it".
type Core ¶
type Core[Tx any] interface { // RegisterExternal registers a redirect-based method and returns its handlers. It // panics on a registration rule, because that is a wiring mistake found at startup: // the registration has no name or its name is already used, the core has served a // request, or reg.Err carries a misuse the registration function found in its // arguments. RegisterExternal(reg *Registration[Tx]) Handlers }
Core is what a method registers on: the Auth that session.NewAuth returned. *session.Auth implements it. Tx is the Auth's storage transaction type, which the method's account rule receives.
type Decision ¶
type Decision struct {
// contains filtered or unexported fields
}
Decision is a sign-in policy's answer, built with Allow, Deny or RequireMFA. A nil Decision denies.
func Deny ¶
func Deny(code sessioninfo.LoginRefusalCode) *Decision
Deny refuses the sign-in with code, or sessioninfo.RefusedByPolicy when code is empty. The policy's own writes are committed.
func RequireMFA ¶
func RequireMFA(factors ...sessioninfo.AuthMethod) *Decision
RequireMFA holds the sign-in as pending until the application completes its MFA step and calls CompletePending with the step-up events. factors are the methods those events may record, the application's own names such as "email-otp"; a completion by any other method is refused. With no factors, any method completes the step.
func (*Decision) Cause ¶
Cause is the cause a Deny decision of one of the library's own rules carries beside ErrSignInDenied (ErrNoTenant, ErrConnectionNotInTenant, ErrDirectoryOnly), nil for a Deny the application built.
func (*Decision) Factors ¶
func (d *Decision) Factors() []sessioninfo.AuthMethod
Factors are the methods a RequireMFA decision accepts for the step-up; none means any.
func (*Decision) Outcome ¶
func (d *Decision) Outcome() PolicyOutcome
Outcome is what the decision does.
func (*Decision) Refusal ¶
func (d *Decision) Refusal() sessioninfo.LoginRefusalCode
Refusal is a Deny decision's code.
type DeclarationReader ¶
type DeclarationReader[Tx any] func(ctx context.Context, tx Tx, tenant accesstypes.Domain) (*TenantDeclaration, error)
DeclarationReader reads a tenant's declaration for the tenant policy, in the sign-in's transaction, typed to the storage's transaction like the other hooks (pgx.Tx on PostgreSQL, *spanner.ReadWriteTransaction on Spanner). It answers nil for a tenant that declares nothing. Spanner may retry the transaction, so the reader must not have side effects outside it.
type DeclaredDirectory ¶
type DeclaredDirectory struct {
Tenant accesstypes.Domain
DefaultSeat accesstypes.Role
}
DeclaredDirectory is one tenant's declaration of a directory, as a DirectoryReader answers it for a stranger's first sign-in: the tenant, and the default seat the tenant gives a person its directory vouched for, the role the sign-in seats them with in the tenant, or "" when the tenant admits its people by invitation only.
type Directory ¶
type Directory struct {
Method sessioninfo.AuthMethod
Connection string
}
Directory is a directory a tenant admits its people through: a sign-in method and the connection its identities carry, the values of Identity.Method and Identity.Connection, which the session's first auth event records too. A Microsoft Entra tenant is named by its tenant id under MethodAzure, a Google Workspace by the name the registration gives it under MethodGoogle, a WorkOS connection by its id under MethodWorkOS.
func (Directory) Organization ¶ added in v0.5.0
Organization reports whether the directory is an organization's: a sign-in method that signs a person in through a directory (sessioninfo.AuthMethod.ThroughDirectory) with a connection that names one organization, so neither of the two values that stand for everyone who is in no organization (PersonalAccounts). It is what a tenant can take as its directory, and what a tenant's declaration admits or refuses a session by: a password, a session the application started itself, an impersonation and a personal account are no organization's directory.
func (Directory) PersonalAccounts ¶ added in v0.5.0
PersonalAccounts reports whether the directory is one of the two values that stand for everyone who is in no organization: any Google account, or Microsoft's personal accounts. Such a value is no organization's directory, so no tenant takes it as its own, and a person who signed in through it belongs to no tenant's directory.
type DirectoryReader ¶
type DirectoryReader[Tx any] func(ctx context.Context, tx Tx, directory Directory) ([]DeclaredDirectory, error)
DirectoryReader reads every tenant's declaration of a directory for a stranger's first sign-in, in the sign-in's first transaction, typed to the storage's transaction like the other hooks: the tenants that declare the directory the identity came through, each with its default seat. A directory some tenant declares belongs to that tenant, and its declaration decides the stranger before the registration's account rule does; a directory no tenant declares, an empty answer, falls to the registration's rule as it would without the reader. Spanner may retry the transaction, so the reader must not have side effects outside it. Set it on the Auth with SetDirectoryAdmission, beside the hook that seats the person.
type DirectorySeat ¶
type DirectorySeat struct {
Tenant accesstypes.Domain
Role accesstypes.Role
}
DirectorySeat is a seat a first sign-in grants: a role in a tenant, the default seat of a directory the tenant declared, written by the application's hook once the user is committed.
type DisabledRoleSyncConfig ¶
type DisabledRoleSyncConfig interface {
RoleSyncConfig
}
DisabledRoleSyncConfig is the type returned by DisableRoleSync: a RoleSyncConfig that disables synchronization.
func DisableRoleSync ¶
func DisableRoleSync() DisabledRoleSyncConfig
DisableRoleSync disables role synchronization for a method: no roles are read, written, or removed at sign-in, and the at-least-one-role gate does not apply; every user the identity provider verifies may sign in. Use it when the application manages roles itself (or uses no roles at all); the provider's role claims remain available to a custom session data resolver through the raw claims.
type Handlers ¶
type Handlers struct {
// Login begins the round trip: it redirects the browser to the provider.
Login http.HandlerFunc
// Callback completes it: it resolves the identity, applies the sign-in policy and
// establishes the session, holds it pending, or refuses it.
Callback http.HandlerFunc
// FrontChannelLogout handles a provider-initiated logout; nil unless the
// registration asked for it.
FrontChannelLogout http.HandlerFunc
}
Handlers are a registered method's HTTP handlers, built by the core.
type IdentityOutcome ¶
type IdentityOutcome int
IdentityOutcome is what a Resolution does with an external identity that is not yet linked to any user. An account rule builds its Resolution with Reject, Link, Provision, Confirm or Standard; Resolution.Outcome reads it back.
const ( // RejectIdentity refuses the sign-in (Reject). It is the zero value, so a nil // Resolution never grants access. The rule's own writes are committed. RejectIdentity IdentityOutcome = iota // LinkIdentity links the identity to an existing user and signs in (Link). LinkIdentity // ProvisionUser creates the user, links the identity to it and signs in (Provision). ProvisionUser // RequireConfirmation holds the identity as pending until the person enters the // password of the existing user it names; the identity is then linked (Confirm). RequireConfirmation // ApplyStandardRule leaves the identity to the library's standard rule (Standard). ApplyStandardRule )
type Issuers ¶
type Issuers interface {
// Contains reports whether iss is one of the set. An empty string never is.
Contains(iss string) bool
// Only returns the set's single issuer when it has exactly one, which a logout
// request that names no issuer is scoped by; a set with several has none, and such
// a request is scoped by the issuers of the set live sessions carry the id under.
Only() (string, bool)
}
Issuers is the set of issuers a registration's tokens may come from. A sign-in's provider session id is recorded under the issuer of the token that arrived (Verified.Issuer), since a provider's session id is unique only within its issuer, and a provider-initiated logout is scoped by the set: by the issuer the request names, when it names one, else by the set's only issuer, or by whichever of the set live sessions carry the id under (Entra sends the id alone). A registration serving one organization has one issuer; one serving listed organizations has several; one serving any organization has every well-formed issuer of its provider. A method without an issuer has none.
func IssuerList ¶
IssuerList returns the set of exactly the issuers listed, empty strings and repeats dropped.
func IssuersMatching ¶
IssuersMatching returns the set of every issuer accept reports true for, such as every tenant issuer of a provider. It has no single issuer: a logout request naming none is scoped by the issuers of the set live sessions carry the id under.
type Kind ¶
type Kind string
Kind is how a sign-in method starts, as the login page renders it.
const ( // KindPassword is a form: the page posts {"username", "password"} to the method's // path and reads the password login's JSON answer. KindPassword Kind = "password" // KindRedirect is a redirect: the page sends the browser to the method's path (a // GET, with ?returnUrl= naming the page to come back to), the provider signs the // person in, and the method's callback brings the browser back. KindRedirect Kind = "redirect" )
type LoginOptions ¶
type LoginOptions struct {
// LoginHint is the account the provider is asked to pick, its login_hint
// parameter, or "" for none. The Google and generic OpenID Connect methods read it
// from ?login_hint= (LoginHint).
LoginHint string
// SelectAccount asks the provider to show its account chooser, its
// prompt=select_account parameter. A login page sets it after a refusal and under
// "Use a different account", so a provider holding one signed-in account does not
// sign that account in again without asking. The Google and Entra methods read it
// from ?prompt=select_account.
SelectAccount bool
}
LoginOptions are what a login request asks of the provider beyond the return address: the hints a login page adds to the provider's authorization request. The provider may ignore them; the identity always comes from the verified token.
type Method ¶
type Method struct {
// Name is the method's name.
Name sessioninfo.AuthMethod
// LoginURL is where refused and pending sign-ins are sent.
LoginURL func() string
// Begin writes the method's state cookie and returns the provider URL the browser
// goes to. returnURL is the sanitized path in the application the browser returns
// to afterwards.
Begin func(ctx context.Context, w http.ResponseWriter, r *http.Request, returnURL string) (string, error)
// Complete verifies the provider's answer into a verified sign-in. Every refusal is a
// sessioninfo.LoginRefusal.
Complete func(ctx context.Context, w http.ResponseWriter, r *http.Request) (*Verified, error)
// SyncRoles reconciles the user's roles to the role names the provider asserted,
// and refuses the sign-in (no_roles) when no recognized role results. The user is
// named as the permission store names them, by the id of their account. It is nil
// when the method synchronizes no roles.
SyncRoles func(ctx context.Context, user accesstypes.User, roleNames []string) error
// RecognizesRoles reports whether SyncRoles would leave the user holding a role:
// at least one of roleNames is a role the application knows. The core asks it
// before the sign-in is resolved, so a person whose roles admit nothing is refused
// (no_roles) before anything is written or an invitation they carry is consumed.
// It is nil when the method synchronizes no roles or cannot tell beforehand;
// SyncRoles then refuses once the session stands.
RecognizesRoles func(ctx context.Context, roleNames []string) (bool, error)
// AdmitsAddress reports whether an identity with this email address could be
// admitted by the method, which the core asks before it sends an invitation to the
// address. It is nil when the method cannot tell, which admits.
AdmitsAddress func(email string) bool
// Audience is how wide the method is, which its registration fixes: the
// organizations it is limited to, or the kind of account it admits. It is what
// opening the method to sign-up admits.
Audience Audience
// AdmitsConnection reports whether an identity that came through connection (the
// Connection its link carries) could sign in through this registration as it is
// configured now: a tenant, a Workspace or a provider the registration still takes.
// The core asks it to judge whether a link is still a means of sign-in, before a
// person's password is removed on the strength of it. It is nil when the method
// cannot tell one connection from another, which admits.
AdmitsConnection func(connection string) bool
// ConnectionName answers the name the registration gives the organization behind a
// connection, in words a person knows: the application's name for a listed
// Microsoft Entra tenant, a Google Workspace's name or the domain of one admitted
// as any Workspace, the application's name for an OpenID Connect provider or the
// host of its issuer. It answers "" for a connection the registration has no name
// for, a tenant listed by its id alone or admitted as any tenant: a sentence then
// says the directory by the label of the registration's button, never by the id.
// It is nil when the method names no connection. The Auth answers a directory's
// name from it (session.AuthAPI.DirectoryName).
ConnectionName func(connection string) string
}
Method is a registered external method as the core drives it.
type NewUser ¶
type NewUser struct {
Username string
PasswordHash *securehash.Hash
Disabled bool
}
NewUser is the user a rule provisions. It has no password unless PasswordHash is set.
type PendingSignInError ¶
type PendingSignInError struct {
// Reason is why the sign-in waits.
Reason sessioninfo.PendingReason
// UserID is the user the sign-in resolved to.
UserID impulse.NullUUID
// Username is that user's username.
Username string
// Tenant is the rule's tenant key for the link to be made.
Tenant string
// Factors are the methods the sign-in policy accepts for the MFA step, for
// PendingMFA; none means any.
Factors []sessioninfo.AuthMethod
}
PendingSignInError is returned by a sign-in that resolved to a user but must wait. Its Reason is sessioninfo.PendingConfirmation when the account rule returned RequireConfirmation, and sessioninfo.PendingMFA when the sign-in policy returned RequireMFA. UserID is the user it waits on. No session is written, but the user resolution and the hooks' own writes are committed. Use errors.As to read it.
func (*PendingSignInError) Error ¶
func (e *PendingSignInError) Error() string
Error describes the pending sign-in.
type Policy ¶
type Policy[Tx any] func(ctx context.Context, tx Tx, req *sessioninfo.NewSessionRequest) (*Decision, error)
Policy is the application's sign-in rule, asked once a sign-in's user is known and before any session exists, for every sign-in method and for a session the application starts for a user it authenticated itself. It is optional: an Auth without one decides a sign-in on the library's own checks (the user exists and is enabled, the identity is linked or resolved, roles reconcile); session.Auth.SetSignInPolicy sets one. It runs in the transaction that inserts the session; the user resolution has committed by then, so the policy can read the user and the rows the account rule wrote, and req.User says how the user was found. The transaction commits unless an error is returned, so a DenySignIn or RequireMFA answer keeps the policy's own writes.
func SuperAdministratorFactor ¶ added in v0.5.0
func SuperAdministratorFactor[Tx any](policy Policy[Tx], check SuperAdministratorCheck) Policy[Tx]
SuperAdministratorFactor returns the rule an Auth decides a sign-in by once it knows who its super administrators are: policy, the application's own rule (nil for none, which allows), and after it the library's: a super administrator signs in with a second factor, whatever the application asks of anyone else. A sign-in the policy allows is held for the library's second factor, the code it mails (sessioninfo.MethodEmailCode), when the person holds the Super Administrator role; it then waits for the code unless the sign-in already carries a second factor, as for any account: the directory's attestation, or a browser the person asked to be remembered, for the period the library remembers one. A decision of the policy that is no plain allow stands as it is: a refusal, and a hold for a factor the policy names itself. The check's error fails the sign-in.
The library's rule stands down for a sign-in through a method that synchronizes roles (the request carries the role names the directory asserted, RoleNames, which is never nil for such a method): there the directory is the authority on who is a super administrator, as on every role, and how its people prove who they are is the directory's to say. The application's own rule is asked of that person as of anyone, and what it decides stands; the check is not asked.
func TenantPolicy ¶
func TenantPolicy[Tx any](roles UserRoleManager, declarations DeclarationReader[Tx], opts ...TenantPolicyOption) Policy[Tx]
TenantPolicy is the library's sign-in rule for an application whose users belong to tenants: a person signs in when one of their tenants admits the way they signed in. The person's tenants are the domains where they hold a role, read through roles, the access library's user manager, and what each tenant admits is its declaration (TenantDeclaration), read through declarations in the sign-in's transaction. A tenant's declaration restricts that tenant alone, so the policy refuses a person only when every tenant that seats them is closed to the way they signed in. The policy decides what the session may be; which of the person's tenants the session then reaches is decided again, tenant by tenant, where the session's tenant list is computed, with TenantDeclaration.Admits over the session's first auth event, and with TenantDeclaration.AdmitsAdministrator for the tenant's own administrators. It never writes. Set it with session.Auth.SetSignInPolicy; Then chains the application's own rule after it, which still refuses whom it refuses.
The rules, in order, once the user is known:
- A super administrator, a person holding the Super Administrator role (accesstypes.RoleCollection.HoldsSuperAdministrator), is admitted on the library's own checks, whatever any tenant declares: the role is the way back in, and no tenant's sign-in settings shut its holder out. A sign-in whose method synchronizes roles is admitted here too (the directory names the person's roles, and the synchronization, which runs once the session stands, refuses a person with none); the application's own directories are admitted by the registration's organization slot already.
- A tenant's own administrators keep a way into their tenant: a person who signs in with a password and administers a tenant that is directory only (UserRoleManager.TenantsAdministered, TenantDeclaration.AdmitsAdministrator) is not refused, and the sign-in is held for the library's second factor, the code it mails (RequireMFA with sessioninfo.MethodEmailCode), whatever else would have admitted it and though the application's own rule would hold nobody: the session reaches that tenant only while it carries a second factor, so one is asked at the sign-in. A rule chained after this one (Then) that holds the sign-in for a factor of its own has its hold stand in this one's place, and the session then carries that factor. A browser the person asked to be remembered passes it, for the period the library remembers one. Nobody but a super administrator and a tenant's own administrators, in their own tenant, enters a directory-only tenant another way than through its directory: a person who holds the administrator's role in every tenant, or through a group kept for the whole application, is held to the declaration like anyone, and so is an administrator who signed in through another organization's directory or with a personal account.
- A person holding a role outside any one tenant is admitted: in the global partition, which is no tenant's and which no declaration governs, or in every tenant domain, whose tenants the policy has no list of. It is no exemption: the session then reaches a tenant only where the tenant's declaration admits it, as anyone's does.
- A person who is a member of no tenant is refused (no_tenant), unless the policy was built with AdmitWithoutTenant.
- The sign-in is admitted when one of the person's tenants admits it (TenantDeclaration.Admits): a tenant that is not directory only admits every sign-in, a password, a personal account, a session the application starts for a user it authenticated itself, and a sign-in through any directory; a tenant that is directory only admits a sign-in through its own directory alone.
- Otherwise every tenant of the person is directory only and none has the way they signed in as its directory: nothing would be reachable, and the sign-in is refused. A sign-in through a directory (Entra, Google, WorkOS, an OpenID Connect provider) is refused with connection_not_in_tenant, and any other with directory_only.
A refusal is a sessioninfo.LoginRefusal with its code, and errors.Is matches ErrSignInDenied and the rule's own cause (ErrNoTenant, ErrConnectionNotInTenant, ErrDirectoryOnly). A role store or reader error fails the sign-in (internal_error). A nil roles or declarations is a wiring mistake and panics.
A stranger, a person no user was created for, never reaches the policy as such: the account rules decide them first, and in a tenanted application the tenants' declarations decide before the registration's rule, through the directory reader and seat hook set with session.Auth.SetDirectoryAdmission (DirectoryReader): a default seat admits and seats the person, so the policy then finds the membership, and a declaration without one refuses them by invitation only, unless they carry another tenant's invitation, which seats them in the tenant that invited them.
func (Policy[Tx]) Then ¶
Then returns the policy that asks p and, unless p refuses the sign-in, asks next: the library's tenant policy (TenantPolicy) first, then the application's own rule for what the tenant policy cannot know. A Deny from p is answered as it is, and next is not asked. When p allows, next's decision is the answer. When p holds the sign-in for a second factor (RequireMFA), next is asked all the same, so a person p holds is still refused by the rule that refuses them: next's refusal stands, and so does a hold of its own, for the factor the application names; when next allows, p's hold is the answer. A nil next is a wiring mistake and panics.
type PolicyOutcome ¶
type PolicyOutcome int
PolicyOutcome is what a Decision does with a sign-in. A policy builds its Decision with Allow, Deny or RequireMFA; Decision.Outcome reads it back.
const ( // DenySignIn refuses the sign-in (Deny). It is the zero value, so a nil Decision // never grants access. The policy's own writes are committed. DenySignIn PolicyOutcome = iota // AllowSignIn establishes the session (Allow). AllowSignIn // HoldForMFA holds the sign-in as pending until the application completes its MFA // step and calls CompletePending (RequireMFA). HoldForMFA )
type Registration ¶
type Registration[Tx any] struct { // Name identifies the registration on the core, where it must be unique. One // method may be registered several times under different names (two Entra // tenants); the name is the application's, such as "azure" or "lakeside-entra". Name string // Method names the method; it is the identity's method and the session's auth // event's. Method sessioninfo.AuthMethod // AccountRule is the application's own rule for an identity of the method that is // not linked to any user yet, nil for none, which leaves every such identity to the // library's standard rule: // the method builds it over the rule the application gave its registration, typed // to the method's identity. AccountRule AccountRule[Tx] // SeededUsers declares that the provider's names are the application's own: an // identity of this registration under the name of a user created ahead is that // user, so the standard rule links the user on the name alone, whatever tenant has // the provider as its directory and whatever the user holds. It is for the provider // a deployment runs for the accounts it seeds, as the persona provider of the test // environments is for the cast, and never for an organization's directory, whose // names are the organization's to assert. SeededUsers bool // Build builds the method over the registration's state cookie, which carries the // browser's half of a round trip to the provider; the core names it for the // registration. Build func(cookies StateCookies) (*Method, error) // FrontChannelLogout asks for the provider-initiated logout handler. FrontChannelLogout bool // Issuers is the set of issuers the registration's tokens may come from, nil for a // method that has none. The core refuses a round trip whose Verified.Issuer is not // in the set, records a sign-in's provider session id under that issuer (a // provider's session id is unique only within its issuer), and scopes the // front-channel logout handler by one of the set: the issuer the request names // (iss), or the set's only issuer when the request names none. A registration that // asks for the handler must declare its issuers; one that declares none records no // provider session id. Issuers Issuers // Err is a misuse the registration function found in its own arguments; the core // panics with it. Err error }
Registration is what a method asks the core to register.
type Resolution ¶
type Resolution struct {
// contains filtered or unexported fields
}
Resolution is an account rule's answer for an unlinked external identity, built with Reject, Link, Provision, Confirm or Standard and refined with ResolutionOptions. A nil Resolution rejects.
func Confirm ¶
func Confirm(userID impulse.UUID, opts ...ResolutionOption) *Resolution
Confirm holds the identity as pending until the person enters the password of the existing user userID. The identity is then linked. A user without a password cannot confirm (the confirmation answers 401), so Confirm is for users that sign in with a password; a password-less user is linked with Link or refused with Reject.
func Link ¶
func Link(userID impulse.UUID, trusted bool, opts ...ResolutionOption) *Resolution
Link links the identity to the existing user userID and signs in. A user that has a password is refused (ErrLinkRequiresConfirmation) unless trusted is set, which is right only for an enterprise connection on a domain the tenant has verified; use Confirm for such a user otherwise. A user without a password (one an external sign-in provisioned) cannot confirm, so the rule's own evidence is the only check: an untrusted link of an identity from another connection than the ones such a user already signs in through is refused (ErrLinkCrossConnection); the same connection, or a user with no identity yet, links. The standard rule's own link of such a user, made on the name, is held to more: it is made only as the user's first identity unless the user holds the identity's verified address (ErrLinkSecondIdentity), and in a tenanted application only when something vouches for it (see AccountRule). Never choose userID by an email address or another claim the identity's provider does not verify, unless the connection itself is one the application trusts, and then say so with trusted.
func Provision ¶
func Provision(user *NewUser, onProvisioned func(ctx context.Context, userID impulse.UUID) error, opts ...ResolutionOption) *Resolution
Provision creates user, links the identity to it, runs onProvisioned and signs in. onProvisioned, nil for none, runs in the rule's transaction once the user is created, so the application can write its own rows for it: capture the transaction in the rule's closure. The rows commit with the user, so the sign-in policy and the custom session data resolver can read them. The user and its link stay even when the sign-in policy then denies the sign-in or holds it for MFA.
func Reject ¶
func Reject(code sessioninfo.LoginRefusalCode) *Resolution
Reject refuses the sign-in with code, or sessioninfo.RefusedIdentityRejected when code is empty. The rule's own writes, such as a record of the refused attempt, are committed.
func Standard ¶
func Standard(opts ...ResolutionOption) *Resolution
Standard leaves the identity to the library's standard rule (see AccountRule), once the custom rule's own checks have passed: the usual case stays the library's, and the rule only refuses or decides what the standard rule cannot know. Tenant replaces the tenant key the standard rule would store.
func (*Resolution) NewUser ¶
func (r *Resolution) NewUser() *NewUser
NewUser is the user a Provision resolution creates.
func (*Resolution) OnProvisioned ¶
OnProvisioned is a Provision resolution's hook, nil for none.
func (*Resolution) Outcome ¶
func (r *Resolution) Outcome() IdentityOutcome
Outcome is what the resolution does.
func (*Resolution) Refusal ¶
func (r *Resolution) Refusal() sessioninfo.LoginRefusalCode
Refusal is a Reject resolution's code.
func (*Resolution) Seats ¶
func (r *Resolution) Seats() []DirectorySeat
Seats are the seats a Provision resolution grants once it has committed, none for none.
func (*Resolution) Tenant ¶
func (r *Resolution) Tenant() string
Tenant is the tenant key the resolution stores on the link.
func (*Resolution) Trusted ¶
func (r *Resolution) Trusted() bool
Trusted reports whether a Link resolution may link a user that has a password.
func (*Resolution) UserID ¶
func (r *Resolution) UserID() impulse.UUID
UserID is the existing user of a Link or Confirm resolution.
type ResolutionOption ¶
type ResolutionOption func(r *Resolution)
ResolutionOption refines a Link, Provision, Confirm or Standard resolution.
func Seats ¶
func Seats(seats ...DirectorySeat) ResolutionOption
Seats grants seats to the user a Provision resolution creates, once the resolution has committed, through the Auth's directory seat hook (session.Auth.SetDirectoryAdmission): the default seats of the directories the tenants declared, which the standard rule adds itself, or a custom rule's own. A resolution that carries seats on an Auth with no hook fails the sign-in.
func Tenant ¶
func Tenant(tenant string) ResolutionOption
Tenant stores tenant, the application's tenant key, on the identity link. The standard rule stores the identity's connection (the Entra tenant id, the application's name for the Google Workspace) unless Standard is given another.
type RoleReconciler ¶
type RoleReconciler struct {
// contains filtered or unexported fields
}
RoleReconciler reconciles a user's role memberships to the role names an identity provider asserted. A method gets one from ReconcilerOf at registration.
func ReconcilerOf ¶
func ReconcilerOf(cfg RoleSyncConfig) (*RoleReconciler, error)
ReconcilerOf validates a method's required role sync slot. It returns nil when role sync is disabled, and an error when the slot is missing or RoleSync was given no manager.
func (*RoleReconciler) RecognizesAny ¶
RecognizesAny reports whether at least one of roleNames is a role the application knows in a place the sync writes: whether RequireRoles would leave the user holding a role. It reads the role catalog and writes nothing, so the core can refuse a sign-in the directory's roles admit nowhere before anything else is written.
func (*RoleReconciler) RequireRoles ¶
func (r *RoleReconciler) RequireRoles(ctx context.Context, username accesstypes.User, roleNames []string) error
RequireRoles reconciles username's roles to roleNames. It refuses the sign-in with RefusedNoRoles when no recognized role results.
type RoleSyncConfig ¶
type RoleSyncConfig interface {
// contains filtered or unexported methods
}
RoleSyncConfig is the required role-synchronization slot of a method whose identity provider asserts the user's roles, such as the Microsoft Entra ID method. Construct the slot with RoleSync to enable synchronization, or with DisableRoleSync to leave role management entirely to the application. There is no default. (The Google Workspace method has its own slot, because its roles come from a group lookup.)
func RoleSync ¶
func RoleSync(manager UserRoleManager) RoleSyncConfig
RoleSync enables directory-driven role synchronization for a method whose identity provider asserts the user's roles: on every sign-in the user's memberships are reconciled to the roles the provider names. A global role is held in the global partition and a domain role in every tenant domain, and a membership the directory does not name, wherever it is held, is removed. The sign-in is refused unless at least one recognized role results.
type StateCookies ¶
type StateCookies interface {
WriteStateCookie(w http.ResponseWriter, values *cookie.Values)
ReadStateCookie(r *http.Request) (values *cookie.Values, readName string, err error)
DeleteStateCookie(w http.ResponseWriter, name string)
}
StateCookies writes and reads a registration's state cookie: the state and PKCE verifier of a round trip to the provider, and the return URL the browser goes to afterwards. The core names the cookie for the registration (OIDC-<name>) and binds it to the registration, so two registrations of one method, and logins with different providers in one browser, never read each other's state. ReadStateCookie's readName is the cookie's name, or "" when the browser carries none for this registration; a state cookie is single-use, so the method passes readName to DeleteStateCookie.
type SuperAdministratorCheck ¶ added in v0.5.0
SuperAdministratorCheck reports whether user, a person as the permission store names them (the id of their account), holds the Super Administrator role (accesstypes.SuperAdministrator). An Auth asks it of every person a sign-in would admit (session.NewAuth is handed it, in session.SuperAdministratorsBy), inside the sign-in's transaction and with its context, so a check that reads a database reads outside that transaction.
func SuperAdministrators ¶ added in v0.5.0
func SuperAdministrators(roles UserRoleManager) SuperAdministratorCheck
SuperAdministrators answers the check over the role store: the person's memberships in the global partition, read through roles, the access library's user manager, and judged by the one test of who is a super administrator (accesstypes.RoleCollection.HoldsSuperAdministrator), the test the tenant policy asks too. On Spanner pass the manager wrapped by resource.SignInRoles, as to TenantPolicy, so the read is made outside the sign-in's transaction. A nil roles is a wiring mistake and panics.
type TenantDeclaration ¶
type TenantDeclaration struct {
// Directories are the directories the tenant admits its people through. A tenant
// has one directory, and a directory is one tenant's: the application's schema and
// its write paths hold both, so the list carries one directory at most. The
// directory seats a stranger at their first sign-in through it (DeclaredDirectory);
// it closes the tenant to nobody until the tenant is directory only.
Directories []Directory
// DirectoryOnly says the tenant's people enter through its directory only: a
// password, a personal account, any other sign-in that is not through a directory,
// and a sign-in through another organization's directory do not reach the tenant.
// The tenant's own administrators alone keep a way in beside the directory, with a
// password and a second factor (AdmitsAdministrator).
DirectoryOnly bool
}
TenantDeclaration is what a tenant declares about who may enter it: the directory its people come through, and whether they come through it only. It is configuration data of the tenant, kept by the application and read for the library by a DeclarationReader. A tenant's declaration restricts that tenant's own door and nobody else's: a tenant that declares nothing, a nil or an empty declaration, admits everyone it seats, however they signed in.
func (*TenantDeclaration) Admits ¶
func (d *TenantDeclaration) Admits(method sessioninfo.AuthMethod, connection string) bool
Admits reports whether the declaration admits a session established through method and connection, as the session's first auth event records them (sessioninfo.SessionData.EstablishedBy). A tenant that is not directory only admits every establishment: a password, a personal account, a step the application recorded under its own name, and a sign-in through any organization's directory, the tenant's own or another's. A tenant that is directory only admits a sign-in through its own directory, the (method, connection) it declares, and nothing else, but for its own administrators, who are asked of AdmitsAdministrator. A personal account (Directory.PersonalAccounts: any Google account, a Microsoft personal account) is no directory, which no tenant can declare, so a directory-only tenant refuses it as it refuses a password. The tenant policy decides with it at sign-in, over every tenant of the person, and the application decides with it again when the session reaches one tenant, where the session's tenant list is computed. It reads nothing: a nil declaration declares nothing.
func (*TenantDeclaration) AdmitsAdministrator ¶ added in v0.5.0
func (d *TenantDeclaration) AdmitsAdministrator(method sessioninfo.AuthMethod, secondFactor, administers bool) bool
AdmitsAdministrator reports whether the declaration admits a session by the administrators' way in: a tenant that is directory only still admits its own administrators, so a tenant whose directory is broken, or whose settings went wrong, is not a tenant nobody can mend. It holds when the tenant is directory only, the session was established by the password method (method), the session carries a second factor (secondFactor: the mailed code, or a remembered browser standing in for it, sessioninfo.SessionData.SecondFactor), and the person administers the tenant (administers): they hold one of the roles the application names as a tenant's administrator's in the tenant itself, inside its period, by a membership of their own or through a group kept in that tenant (the access library's Controller.UserAdministersTenant). A role held in every tenant, or through a group kept for the whole application, is no such holding, so the application's own people are kept out with everyone else. An administrator who signed in through another organization's directory or with a personal account is kept out too: the way in is the password, and nothing wider. It is the one decision both places ask: the tenant policy at sign-in, with the second factor it is about to demand taken as given, and the application when the session reaches the tenant, with the session's own. It opens no other tenant: the same session reaches the person's other tenants by those tenants' own declarations.
type TenantPolicyOption ¶
type TenantPolicyOption func(settings *tenantPolicySettings)
TenantPolicyOption refines the tenant policy.
func AdmitWithoutTenant ¶
func AdmitWithoutTenant() TenantPolicyOption
AdmitWithoutTenant admits a person who is a member of no tenant instead of refusing them (no_tenant). The self-service shape of an application needs it: a stranger signs in, then creates their organization, whose first membership the application writes; until then the session reaches no tenant.
type UserRoleManager ¶
type UserRoleManager interface {
// UserRoles lists the roles the user holds in the given places. With no
// scopes it lists every membership the user holds, keyed by where each is
// held.
UserRoles(ctx context.Context, user accesstypes.User, scopes ...accesstypes.PolicyScope) (accesstypes.RoleCollection, error)
// TenantsAdministered lists the tenants the user administers: the tenant domains
// where they hold, in the tenant itself and inside its period, one of the roles the
// application names as a tenant's administrator's, by a membership of their own or
// through a group kept in that tenant. A role held in every tenant, or through a
// group kept for the whole application, lists no tenant. The tenant policy reads it
// for the administrators' way into a directory-only tenant
// (TenantDeclaration.AdmitsAdministrator); the role synchronization does not. A
// store that names no administrator role answers none.
TenantsAdministered(ctx context.Context, user accesstypes.User) ([]accesstypes.Domain, error)
// ResolveRole returns the role held in the place under name, matched without
// regard to case, in the spelling the store holds it: in the global
// partition for a global role, in every tenant domain for a domain default
// role or a custom role created in every domain. Not found is (“”, false,
// nil); two roles differing only in case with no exact match is an error.
ResolveRole(ctx context.Context, scope accesstypes.PolicyScope, name string) (accesstypes.Role, bool, error)
// AddUserRoles writes the user's membership in the roles, held in the place.
AddUserRoles(ctx context.Context, scope accesstypes.PolicyScope, user accesstypes.User, roles ...accesstypes.Role) error
// DeleteUserRoles removes the user's membership in the roles held in the place.
DeleteUserRoles(ctx context.Context, scope accesstypes.PolicyScope, user accesstypes.User, roles ...accesstypes.Role) error
}
UserRoleManager defines the role store operations required by OIDC role synchronization (see RoleSync) and by the tenant policy (see TenantPolicy), which reads what a person holds and which tenants they administer. The sync writes memberships in two places, the global partition and every tenant domain: a role that exists in the global partition is held there, a role that exists in every tenant domain is held there, and a membership the directory does not name is removed wherever it is held.
A directory names roles without regard to case (a Google group is an email address, and the groups lookup lowercases what it reads), so the sync hands the store a name and takes back the role in the spelling the store holds it: what the person holds and what the directory names compare as one set of names, and every write carries the store's spelling.
ResolveRole errors must be returned, never flattened to "not found": the sync is reconcile-with-delete, and a swallowed store error would silently remove a user's valid role membership at login.
type Verified ¶
type Verified struct {
// Identity is who the provider says signed in, keyed by the method, its connection
// and the provider's immutable subject, with the sign-in name the standard account
// rules use and whether the account is a guest of its directory.
Identity *sessioninfo.Identity
// ReturnURL is the sanitized path in the application the browser goes to afterwards.
ReturnURL string
// RoleNames are the role names the provider asserted. They are nil when the method
// synchronizes no roles, and never nil when it does: "no roles asserted" is an empty
// list.
RoleNames []string
// ProviderSessionID is the provider's own session id for this sign-in (an OpenID
// Connect sid claim), which a provider-initiated logout names; "" when the method
// has none.
ProviderSessionID string
// Issuer is the issuer of the token the round trip verified, "" when the method
// has none. It must be one of the registration's Issuers when those are declared;
// the core records ProviderSessionID under it.
Issuer string
}
Verified is the result of a method's completed round trip.