Documentation
¶
Overview ¶
Package sso administers persisted enterprise OpenID Connect providers.
Index ¶
- Variables
- func DomainChallengeRecord(id string, expiresAt time.Time) auth.VerificationRecord
- func DomainMatch(domain, list string) int
- func DomainTargets(id, identifier, rawDomains string) ([]string, error)
- func LogoutRequestRecord(id string, expiresAt time.Time) auth.VerificationRecord
- func LogoutSessionRecord(id, userID string, expiresAt time.Time) auth.VerificationRecord
- func MutableProviderID(id string) bool
- func New(o Options) (auth.Plugin, error)
- func SAMLTrustChanged(current, next SAMLConfig) bool
- func SameSAMLIdentity(current, next SAMLConfig) bool
- type AccountKey
- type Actor
- type AssertionReceipt
- type BrowserProvider
- type BrowserStore
- type Certificates
- type Config
- type DataEncryptionAlgorithm
- type DeletionStore
- type DigestAlgorithm
- type DomainChallenge
- type DomainOrganization
- type DomainOrganizationStore
- type DomainStore
- type DomainVerificationOptions
- type KeyEncryptionAlgorithm
- type MutationGuard
- type OIDCDirectory
- type OIDCDirectoryPolicy
- type Options
- type OrganizationRoleInput
- type PrivateKey
- type PrivateKeyRequest
- type Provider
- type ProviderChange
- type ProviderField
- type ProviderFieldStore
- type ProviderMutation
- type ProviderUpdateStore
- type ProviderUser
- type Provisioning
- type PublicConfig
- type PublicProvider
- type PublicSAMLConfig
- type Registered
- type ResolutionAction
- type SAMLAlgorithms
- type SAMLCertificateInfo
- type SAMLConfig
- type SAMLDirectory
- type SAMLDirectoryPolicy
- type SAMLEncryption
- type SAMLIDPLogout
- type SAMLIDPLogoutStore
- type SAMLIDPMetadata
- type SAMLLogoutIdentity
- type SAMLLogoutRequest
- type SAMLLogoutStore
- type SAMLMapping
- type SAMLMetadataStore
- type SAMLOptions
- type SAMLSPMetadata
- type SAMLService
- type SAMLStore
- type Selector
- type SignatureAlgorithm
- type Store
- type TXTResolver
- type UserResolution
- type UserResolutionInput
- type UserResolutionStore
- type VerificationGater
Constants ¶
This section is empty.
Variables ¶
var ( ErrDomainVerified = &auth.APIError{Status: 409, Code: "DOMAIN_VERIFIED", Message: "Domain has already been verified"} ErrDomainUnverified = apiError(401, "Provider domain has not been verified") ErrNoChallenge = &auth.APIError{Status: 404, Code: "NO_PENDING_VERIFICATION", Message: "No pending domain verification exists"} ErrDomainChanged = &auth.APIError{Status: 409, Code: "SSO_PROVIDER_CHANGED", Message: "SSO provider changed while domain verification was in progress. Reload the provider and try again"} ErrInvalidDNSLabel = &auth.APIError{Status: 400, Code: "INVALID_VERIFICATION_IDENTIFIER", Message: "The DNS verification identifier must be a single label using letters, digits, underscores and hyphens"} ErrLabelTooLong = &auth.APIError{Status: 400, Code: "IDENTIFIER_TOO_LONG", Message: "Verification identifier exceeds the DNS label limit of 63 characters"} )
var ( ErrSAMLLogoutSession = apiError(400, "This browser session has no available SAML logout record") ErrSAMLLogoutResponse = &auth.APIError{Status: 400, Code: "INVALID_LOGOUT_RESPONSE", Message: "Invalid LogoutResponse"} )
var ( ErrUnauthenticated = apiError(401, "Unauthorized") ErrLimit = apiError(403, "You have reached the maximum number of SSO providers") ErrDisabled = apiError(403, "SSO provider registration is disabled") ErrDuplicate = apiError(422, "SSO provider with this providerId already exists") ErrForbidden = apiError(403, "You don't have access to this provider") ErrNotMember = apiError(400, "You are not a member of the organization") ErrOrgRole = apiError(403, "You must be an organization owner or admin to register SSO providers") ErrMissing = apiError(404, "Provider not found") // ErrNoSelector answers a sign-in whose organizationSlug names no // organization and that names no provider or domain either. ErrNoSelector = apiError(400, "providerId, orgId or domain is required") )
var ErrAssertionUsed = apiError(400, "SAML assertion has already been consumed")
var ErrChanged = &auth.APIError{Status: 409, Code: "SSO_PROVIDER_CHANGED", Message: "The enterprise provider changed during authentication"}
var ErrInvalidSAML = apiError(400, "Invalid or unsupported SAML configuration")
var ErrLinkedIdentity = &auth.APIError{Status: 409, Message: "Cannot change SSO provider identity fields while linked accounts exist"}
var ErrMetadataStorageSize = &auth.APIError{Status: 400, Message: "SAML configuration exceeds the database column capacity"}
var ErrMutationRejected = &auth.APIError{Status: 409, Code: "SSO_PROVIDER_MUTATION_REJECTED", Message: "SSO provider mutation is not allowed"}
var ErrSAMLLogoutRequest = &auth.APIError{Status: 400, Code: "INVALID_LOGOUT_REQUEST", Message: "Invalid LogoutRequest"}
var ErrUnclassifiedAccounts = &auth.APIError{Status: 409, Code: "SSO_ACCOUNT_ORIGIN_REQUIRED", Message: "An existing account link requires source reconciliation"}
ErrUnclassifiedAccounts requires a trusted operator to establish the origin of preexisting canonical account rows before a provider can be deleted.
Functions ¶
func DomainChallengeRecord ¶
func DomainChallengeRecord(id string, expiresAt time.Time) auth.VerificationRecord
DomainChallengeRecord is a provider's DNS verification token as a verification record. It proves a domain rather than an account, so it names no owner, and it never carries the token or the DNS name it is published at.
func DomainMatch ¶
DomainMatch returns the length of the most specific DNS suffix, or -1 for no match.
func DomainTargets ¶
DomainTargets returns the normalized domains for one well-formed challenge. Requiring one DNS label keeps proof under the registered domain.
func LogoutRequestRecord ¶
func LogoutRequestRecord(id string, expiresAt time.Time) auth.VerificationRecord
LogoutRequestRecord is a pending SP-initiated logout as a verification record. It binds a browser rather than an account, so it names no owner, and it never carries the request ID, RelayState, browser digest or return URL.
func LogoutSessionRecord ¶
func LogoutSessionRecord(id, userID string, expiresAt time.Time) auth.VerificationRecord
LogoutSessionRecord is a SAML logout binding as a verification record: the link single logout keeps between a SAML sign-in's session and the IdP session that issued it. id is the stored row's ID. It names the session's user and never carries the NameID, SessionIndex or token digest the row stores.
func MutableProviderID ¶
MutableProviderID reports whether an identifier can belong to an enterprise directory. Host-configured social provider names are checked separately.
func SAMLTrustChanged ¶
func SAMLTrustChanged(current, next SAMLConfig) bool
SAMLTrustChanged compares the signing anchors and the IdP request-signing policy.
func SameSAMLIdentity ¶
func SameSAMLIdentity(current, next SAMLConfig) bool
SameSAMLIdentity reports whether a change preserves the authority that created previously linked accounts: the IdP entity and sign-in services, the SP entity, the NameID format, the audience and the assertion signing policy, as another runtime compares them. Keys can rotate independently.
Types ¶
type AccountKey ¶
type AccountKey struct {
// Issuer is the ID token's iss for OIDC, or the IdP entity ID for SAML.
Issuer string
// AccountID is the ID token's sub for OIDC, or the signed NameID for
// SAML; compare it case-sensitively.
AccountID string
}
AccountKey names the external account a sign-in proves.
type AssertionReceipt ¶
type AssertionReceipt struct {
Issuer, ID string
Logout *SAMLLogoutIdentity
}
type BrowserProvider ¶
type BrowserStore ¶
type BrowserStore interface {
auth.OAuthIdentityStore
FindBrowserProvider(context.Context, Selector) (BrowserProvider, error)
// role is the organization role to provision, or "" for none.
CompleteEnterpriseLogin(ctx context.Context, reference string, role string, provider, subject string, tokens auth.OAuthTokens, user auth.User, session auth.StoredSession, opts auth.OAuthLoginOptions) (auth.User, bool, error)
}
BrowserStore resolves and completes enterprise sign-ins. Their flows are kept by the auth instance's OAuthStateStrategy. CompleteEnterpriseLogin applies opts.ProfileFields: Create for a new user, and Update, when set, to the returning owner.
type Certificates ¶
type Certificates []string
Certificates accepts either a PEM string or a list for certificate rotation.
func (Certificates) MarshalJSON ¶
func (cs Certificates) MarshalJSON() ([]byte, error)
func (*Certificates) UnmarshalJSON ¶
func (cs *Certificates) UnmarshalJSON(raw []byte) error
type Config ¶
type Config struct {
Issuer string `json:"issuer,omitempty"`
ClientID string `json:"clientId"`
ClientSecret string `json:"clientSecret"`
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
TokenEndpoint string `json:"tokenEndpoint,omitempty"`
JWKSEndpoint string `json:"jwksEndpoint,omitempty"`
UserInfoEndpoint string `json:"userInfoEndpoint,omitempty"`
DiscoveryEndpoint string `json:"discoveryEndpoint,omitempty"`
TokenEndpointAuthentication string `json:"tokenEndpointAuthentication,omitempty"`
PKCE *bool `json:"pkce,omitempty"`
Scopes []string `json:"scopes,omitempty"`
Mapping map[string]any `json:"mapping,omitempty"`
OverrideUserInfo bool `json:"overrideUserInfo"`
// PrivateKeyID names the private_key_jwt key: ResolvePrivateKey
// receives it as KeyID and the assertion carries it as kid.
PrivateKeyID string `json:"privateKeyId,omitempty"`
// PrivateKeyAlgorithm signs the private_key_jwt assertion; it defaults
// to the resolved key's algorithm, then RS256.
PrivateKeyAlgorithm string `json:"privateKeyAlgorithm,omitempty"`
}
type DataEncryptionAlgorithm ¶
type DataEncryptionAlgorithm string
DataEncryptionAlgorithm is an XML Encryption content cipher URI. This service decrypts AES-128, AES-192 and AES-256 in GCM or CBC mode, CBC only inside a Response the IdP signed.
const ( DataEncryptionTripleDESCBC DataEncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc" DataEncryptionAES128CBC DataEncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#aes128-cbc" DataEncryptionAES192CBC DataEncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#aes192-cbc" DataEncryptionAES256CBC DataEncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#aes256-cbc" DataEncryptionAES128GCM DataEncryptionAlgorithm = "http://www.w3.org/2009/xmlenc11#aes128-gcm" DataEncryptionAES192GCM DataEncryptionAlgorithm = "http://www.w3.org/2009/xmlenc11#aes192-gcm" DataEncryptionAES256GCM DataEncryptionAlgorithm = "http://www.w3.org/2009/xmlenc11#aes256-gcm" )
The XML Encryption content ciphers. Triple DES is deprecated.
type DeletionStore ¶
type DeletionStore interface {
DeleteSSOProvider(ctx context.Context, actor Actor, providerID, recordID string, guard MutationGuard) error
}
DeletionStore performs a direct-session and tenant authorization check, then atomically deletes exactly the named record and its account links. A custom store calls guard as MutationGuard describes: on a snapshot, outside its transaction, before a commit that rechecks the snapshot.
type DigestAlgorithm ¶
type DigestAlgorithm string
DigestAlgorithm is an XML Signature digest method URI.
const ( DigestSHA1 DigestAlgorithm = "http://www.w3.org/2000/09/xmldsig#sha1" DigestSHA256 DigestAlgorithm = "http://www.w3.org/2001/04/xmlenc#sha256" DigestSHA384 DigestAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#sha384" DigestSHA512 DigestAlgorithm = "http://www.w3.org/2001/04/xmlenc#sha512" )
The XML Signature digests. SHA-1 is deprecated and always refused.
type DomainChallenge ¶
type DomainChallenge struct{ ProviderID, Domain, Identifier, Token, Scope string }
DomainChallenge is a pending DNS challenge bound to the exact directory and domain set. Scope is an opaque store identifier. The token is public only to an authorized manager.
type DomainOrganization ¶
DomainOrganization is the provider through which a verified email domain selects one organization. Ambiguous reports a domain that maps to several organizations, which joins none.
type DomainOrganizationStore ¶
type DomainOrganizationStore interface {
// SSODomainOrganization returns the first provider, by provider ID,
// that holds a current DNS proof for domain and belongs to an
// organization, and false when there is none, no organization table, or
// the user with this ID and email is already a member or holds a pending
// invitation there.
SSODomainOrganization(ctx context.Context, domain, userID, email string) (DomainOrganization, bool, error)
// AddSSODomainMember adds the user with role unless they are already a
// member or hold a pending invitation, within the organization's limits.
AddSSODomainMember(ctx context.Context, organizationID, userID, email, role string) error
}
DomainOrganizationStore finds and joins the organization a verified email domain selects after a social sign-in, with DomainVerification on.
type DomainStore ¶
type DomainStore interface {
CheckSSODomainSchema(context.Context) error
FindVerifiedBrowserProvider(context.Context, Selector) (BrowserProvider, error)
CreateSSODomainProvider(ctx context.Context, actor Actor, provider Provider, limit int, identifier string) (string, error)
SSODomainChallenge(ctx context.Context, actor Actor, providerID, identifier string, issue bool) (DomainChallenge, error)
// ConfirmSSODomain is a trusted server operation. Its caller must first observe
// the challenge token at every domain using the configured DNS resolver.
ConfirmSSODomain(context.Context, Actor, DomainChallenge) error
// SSODomainVerified matches the captured reference before authorization or token exchange.
// An empty reference requests the latest management projection.
SSODomainVerified(ctx context.Context, provider Provider, reference string) (bool, error)
// SSODomainRequired reports a persisted opt-in across differently configured nodes.
SSODomainRequired(context.Context, Provider) (bool, error)
CompleteVerifiedEnterpriseLogin(ctx context.Context, ref string, role string, id, subject string, tokens auth.OAuthTokens, user auth.User, session auth.StoredSession, opts auth.OAuthLoginOptions) (auth.User, bool, error)
}
type DomainVerificationOptions ¶
type DomainVerificationOptions struct {
// TokenPrefix defaults to "plain-auth-token". A prefix is one DNS label fragment.
TokenPrefix string
// Resolver defaults to the system resolver.
Resolver TXTResolver
}
type KeyEncryptionAlgorithm ¶
type KeyEncryptionAlgorithm string
KeyEncryptionAlgorithm is an XML Encryption key transport URI. This service decrypts KeyEncryptionRSAOAEP, with a SHA-1 or SHA-256 digest, and KeyEncryptionRSAOAEPSHA256, with a SHA-1, SHA-256, SHA-384 or SHA-512 digest and MGF1. SHA-1 there is the OAEP hash, which collisions do not weaken.
const ( KeyEncryptionRSA15 KeyEncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#rsa-1_5" KeyEncryptionRSAOAEP KeyEncryptionAlgorithm = "http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p" KeyEncryptionRSAOAEPSHA256 KeyEncryptionAlgorithm = "http://www.w3.org/2009/xmlenc11#rsa-oaep" )
The XML Encryption key transports. RSA 1.5 is deprecated.
type MutationGuard ¶
type MutationGuard func(context.Context, ProviderMutation) error
MutationGuard reviews a provider deletion, metadata replacement or general update. It runs outside the store's transaction on a snapshot of the locked provider, so it may read through the store or the application's database. The store then locks the provider again and commits only when it reaches the same snapshot, asking the guard again otherwise, up to three times. Return an error to deny the operation; nothing is written. Another runtime runs it inside the transaction.
type OIDCDirectory ¶
type OIDCDirectory struct {
RecordID, Reference, ProviderID, Issuer, ClientID, OrganizationID string
}
OIDCDirectory identifies the current OIDC registration for a host's IdP-initiated sign-in policy. RecordID changes on re-registration and Reference on any configuration change other than the client secret.
type OIDCDirectoryPolicy ¶
type OIDCDirectoryPolicy func(context.Context, OIDCDirectory) (bool, error)
OIDCDirectoryPolicy approves restarting a stateless callback for a reviewed provider. A nil policy disables IdP-initiated OIDC sign-in. Return an error to fail closed.
type Options ¶
type Options struct {
// SAML enables service-provider initiated sign-in with signed assertions.
SAML *SAMLOptions
// ProviderAdditionalFields declares extra provider columns, also declared
// in schema.AdditionalFields.SSOProvider. Registration and update take
// them at the top level of the body, and responses return all but Hidden
// ones. They are not part of the provider's identity.
ProviderAdditionalFields map[string]ProviderField
// DomainVerification enables DNS ownership checks for managed OIDC domains.
DomainVerification *DomainVerificationOptions
// GuardProviderMutation reviews a provider deletion, SAML metadata
// replacement or general update after the exact provider and its
// authorization are checked. It runs outside the store's transaction on a
// snapshot of the locked provider and its linked accounts, and the store
// commits only if it locks the same snapshot again, asking again up to
// three times. Keep it free of side effects; an error denies the
// operation and nothing is written.
GuardProviderMutation MutationGuard
// The shared callback is always {basePath}/sso/callback; another runtime
// also accepts another path or a full URL.
SharedCallback bool
// DisableImplicitSignUp requires requestSignUp before creating an account.
DisableImplicitSignUp bool
// DefaultOverrideUserInfo stores overrideUserInfo on every new OIDC
// registration, whatever the request says.
DefaultOverrideUserInfo bool
// DisableOrganizationProvisioning leaves membership management to the application.
DisableOrganizationProvisioning bool
// DefaultOrganizationRole is the role a provider's organization gives a
// user it provisions at sign-in: member, the default, or admin.
DefaultOrganizationRole string
// ResolveOrganizationRole chooses that role, member or admin, in place of
// DefaultOrganizationRole. It runs before the sign-in transaction, for
// every sign-in through a provider with an organization, so its user is
// the provider's view with no stored ID and it runs for an existing member
// too; another runtime runs it after storing the user, for a new member
// only. An error or panic fails the sign-in with its API error or 500.
ResolveOrganizationRole func(context.Context, OrganizationRoleInput) (string, error)
// A nil ProvidersLimit allows ten registrations per creator. Zero disables registration.
ProvidersLimit *int
// ResolveProvidersLimit returns how many providers the signed-in user may
// register, in place of ProvidersLimit. Zero refuses that user's
// registrations with 403 and a negative number counts as reached. It runs
// before the store's transaction; an error fails the registration.
ResolveProvidersLimit func(context.Context, auth.User) (int, error)
// ResolvePrivateKey supplies the signing key for a provider whose
// tokenEndpointAuthentication is private_key_jwt. It runs before each
// token request, outside any store transaction. Without it,
// registration refuses private_key_jwt.
ResolvePrivateKey func(context.Context, PrivateKeyRequest) (PrivateKey, error)
// AllowIDPInitiatedOIDC restarts a callback that reaches
// /sso/callback/{providerId} with a code and no state, for providers it
// approves. The code is discarded and a new authorization with a fresh
// state, nonce and PKCE verifier starts, returning to the host root. It
// runs outside any store transaction and cannot request sign-up.
// Another runtime enables this on providers defined in code; without
// them the host approves stored registrations.
AllowIDPInitiatedOIDC OIDCDirectoryPolicy
// ResolveUser maps every verified enterprise identity to a user:
// continue by the built-in rules, link it to a chosen user or reject the
// sign-in. It runs after the protocol identity is verified and before the
// sign-in transaction, never inside it, so it may read through the store
// or the application's database; the store then locks the chosen user
// and the identity and refuses a decision they no longer allow. With it,
// every OIDC sign-in needs an ID token. It needs a store implementing
// UserResolutionStore.
ResolveUser func(context.Context, UserResolutionInput) (UserResolution, error)
// ProvisionUser runs after an enterprise sign-in creates a user and its
// account, outside any transaction and before the session cookie is set.
// An *auth.APIError is the response and any other error, or a panic,
// answers 500;
// either way the session is removed, the user stays and, without
// ProvisionUserOnEveryLogin, the callback does not run for that user
// again.
ProvisionUser func(context.Context, Provisioning) error
// ProvisionUserOnEveryLogin runs ProvisionUser on every enterprise
// sign-in, not only the one that creates the user. Keep the callback
// idempotent.
ProvisionUserOnEveryLogin bool
// HTTPClient supplies discovery transport and optional TLS settings.
HTTPClient *http.Client
}
type OrganizationRoleInput ¶
type OrganizationRoleInput struct {
// UserID is the stored user's ID for an assignment by verified email
// domain after a social sign-in; it is empty for a provider sign-in,
// whose user may not be stored yet.
UserID string
User ProviderUser
// UserInfo is the mapped provider profile, with the raw claims or SAML
// attributes in Data.
UserInfo auth.OAuthProfile
// Token holds the OIDC tokens; it is nil for SAML.
Token *auth.OAuthTokens
Provider Provider
}
OrganizationRoleInput describes a sign-in for ResolveOrganizationRole. It runs before the sign-in transaction, so User is the provider's view of the user.
type PrivateKey ¶
PrivateKey is the signing key ResolvePrivateKey returns. Set exactly one of PEM, one PKCS#8 PRIVATE KEY block, and JWK, a private JSON Web Key. KeyID and Algorithm apply when the provider's privateKeyId and privateKeyAlgorithm are unset.
type PrivateKeyRequest ¶
type PrivateKeyRequest struct {
// Another runtime passes only the provider ID, key ID and issuer; the
// record and tenant let a host bind keys to one registration.
RecordID, ProviderID, OrganizationID, UserID string
KeyID, Issuer string
}
PrivateKeyRequest names the provider whose token request needs a private_key_jwt client assertion. KeyID and Issuer come from the stored configuration, which the registrant chooses. Bind keys to RecordID, which changes when a provider ID is deleted and registered again, or to OrganizationID.
type Provider ¶
type Provider struct {
ID string `json:"id"`
ProviderID string `json:"providerId"`
Issuer string `json:"issuer"`
Domain string `json:"domain"`
UserID string `json:"userId"`
OrganizationID *string `json:"organizationId,omitempty"`
OIDC *Config `json:"oidcConfig"`
SAML *SAMLConfig `json:"samlConfig,omitempty"`
// AdditionalFields holds the declared provider fields by name, Hidden
// ones included.
AdditionalFields map[string]any `json:"-"`
}
type ProviderChange ¶
ProviderChange derives a managed provider's next issuer, domain and OIDC configuration from the row the store has locked, and reports whether the issuer, client ID or an endpoint changed. That flag does not cover the claim mapping, which the store compares itself.
type ProviderField ¶
type ProviderField = auth.SessionField
ProviderField declares an additional column on the SSO provider table. Declare the same map in schema.AdditionalFields.SSOProvider.
type ProviderFieldStore ¶
type ProviderFieldStore interface {
WithSSOProviderFields(map[string]ProviderField) (auth.Store, error)
}
ProviderFieldStore binds declared provider fields to a store view that writes and reads their columns.
type ProviderMutation ¶
type ProviderMutation struct {
Action, ID, ProviderID, Reference string
OrganizationID *string
LinkedAccounts int
AuthenticationBoundaryChanged bool
}
ProviderMutation contains the locked provider identity and a snapshot of its exact provider namespace. Reference excludes the confidential client secret.
type ProviderUpdateStore ¶
type ProviderUpdateStore interface {
UpdateSSOProvider(ctx context.Context, actor Actor, id, recordID string, change ProviderChange, guard MutationGuard) (Provider, error)
}
ProviderUpdateStore applies a general provider update under a live direct-session and tenant check. It locks the exact record, applies change to it, counts its linked accounts, asks guard as MutationGuard describes, and refuses an identity change while accounts are linked. A change to the domain, the identity or the OIDC claim mapping resets a DNS proof, because the mapping chooses the email the proof vouches for; other changes carry it forward.
type ProviderUser ¶
ProviderUser is the normalized profile the provider asserted. EmailVerified is false unless the provider's verification is trusted (SAMLOptions.TrustEmailVerified with mapping.emailVerified). Mapped extra fields are not included; read other claims from UserResolutionInput.Claims.
type Provisioning ¶
type Provisioning struct {
// User is the signed-in user as stored.
User auth.User
// UserInfo is the mapped provider profile, with the raw claims or SAML
// attributes in Data.
UserInfo auth.OAuthProfile
// Token holds the OIDC tokens; it is nil for SAML.
Token *auth.OAuthTokens
// Provider is the provider the sign-in went through, with its
// configuration.
Provider Provider
}
Provisioning is what ProvisionUser receives after an enterprise sign-in.
type PublicConfig ¶
type PublicConfig struct {
ClientIDLastFour string `json:"clientIdLastFour"`
DiscoveryEndpoint string `json:"discoveryEndpoint,omitempty"`
AuthorizationEndpoint string `json:"authorizationEndpoint,omitempty"`
TokenEndpoint string `json:"tokenEndpoint,omitempty"`
JWKSEndpoint string `json:"jwksEndpoint,omitempty"`
UserInfoEndpoint string `json:"userInfoEndpoint,omitempty"`
TokenEndpointAuthentication string `json:"tokenEndpointAuthentication,omitempty"`
PKCE *bool `json:"pkce,omitempty"`
Scopes []string `json:"scopes,omitempty"`
}
type PublicProvider ¶
type PublicProvider struct {
SAML *PublicSAMLConfig `json:"samlConfig,omitempty"`
ProviderID string `json:"providerId"`
Type string `json:"type"`
Issuer string `json:"issuer"`
Domain string `json:"domain"`
OrganizationID *string `json:"organizationId"`
DomainVerified bool `json:"domainVerified"`
OIDC *PublicConfig `json:"oidcConfig,omitempty"`
SPMetadataURL string `json:"spMetadataUrl"`
// AdditionalFields holds the declared provider fields the response shows.
AdditionalFields map[string]any `json:"-"`
}
func (PublicProvider) MarshalJSON ¶
func (p PublicProvider) MarshalJSON() ([]byte, error)
MarshalJSON writes the provider's declared fields beside its keys.
type PublicSAMLConfig ¶
type PublicSAMLConfig struct {
EntryPoint string `json:"entryPoint"`
CallbackURL string `json:"callbackUrl,omitempty"`
IDPInitiatedCallbackURL string `json:"idpInitiatedCallbackUrl,omitempty"`
Audience string `json:"audience,omitempty"`
WantAssertionsSigned *bool `json:"wantAssertionsSigned,omitempty"`
AuthnRequestsSigned *bool `json:"authnRequestsSigned,omitempty"`
IdentifierFormat string `json:"identifierFormat,omitempty"`
SignatureAlgorithm string `json:"signatureAlgorithm,omitempty"`
DigestAlgorithm string `json:"digestAlgorithm,omitempty"`
// Certificate summarizes each configured signing certificate.
Certificate []SAMLCertificateInfo `json:"certificate,omitempty"`
}
type Registered ¶
type Registered struct {
Provider
RedirectURI string `json:"redirectURI"`
SAMLConfig any `json:"samlConfig"`
DomainVerified *bool `json:"domainVerified,omitempty"`
DomainVerificationToken string `json:"domainVerificationToken,omitempty"`
// AdditionalFields holds the declared provider fields the response shows.
AdditionalFields map[string]any `json:"-"`
}
func (Registered) MarshalJSON ¶
func (r Registered) MarshalJSON() ([]byte, error)
MarshalJSON writes the registered provider's declared fields beside its keys.
type ResolutionAction ¶
type ResolutionAction string
ResolutionAction is what a ResolveUser decision does with a verified enterprise identity.
const ( // ResolveContinue signs in by the built-in rules. ResolveContinue ResolutionAction = "continue" // ResolveLink signs the identity in to a chosen user. ResolveLink ResolutionAction = "link" // ResolveReject refuses the sign-in. ResolveReject ResolutionAction = "reject" )
type SAMLAlgorithms ¶
type SAMLAlgorithms struct {
// AllowedSignatureAlgorithms lists the signature methods a response may
// use and a directory's samlConfig.signatureAlgorithm may name.
AllowedSignatureAlgorithms []SignatureAlgorithm
// AllowedDigestAlgorithms lists the digests a directory's
// samlConfig.digestAlgorithm may name. Unlike another runtime, the list
// also applies to the digests of response signatures.
AllowedDigestAlgorithms []DigestAlgorithm
// AllowedKeyEncryptionAlgorithms lists the key transports an encrypted
// assertion may use. The SP metadata advertises them in this order.
AllowedKeyEncryptionAlgorithms []KeyEncryptionAlgorithm
// AllowedDataEncryptionAlgorithms lists the content ciphers an encrypted
// assertion may use. The SP metadata advertises them in this order.
AllowedDataEncryptionAlgorithms []DataEncryptionAlgorithm
}
SAMLAlgorithms narrows the XML signature and encryption algorithms SAML responses and directory configurations may use. An empty list accepts every supported algorithm of its kind. Deprecated algorithms (SHA-1 signatures and digests, RSA 1.5 and Triple DES) are always refused and cannot be listed.
Deprecated algorithms have no warn or allow mode, where another runtime warns and accepts them by default: SHA-1 admits chosen-prefix collisions, RSA 1.5 key transport is a Bleichenbacher padding oracle against XML Encryption, and Triple DES has a 64-bit block. The XML library enables RSA 1.5 and Triple DES only through its process-wide decrypter registry, so one host opting in would weaken every SAML consumer in the process.
type SAMLCertificateInfo ¶
type SAMLCertificateInfo struct {
// FingerprintSHA256 is the SHA-256 of the certificate as uppercase,
// colon-separated hex.
FingerprintSHA256 string `json:"fingerprintSha256,omitempty"`
// NotBefore and NotAfter are UTC times such as "Jan 2 15:04:05 2026 GMT".
NotBefore string `json:"notBefore,omitempty"`
NotAfter string `json:"notAfter,omitempty"`
// PublicKeyAlgorithm is RSA, EC, ED25519 or UNKNOWN; another runtime
// also names DSA keys, which SAML directories do not use.
PublicKeyAlgorithm string `json:"publicKeyAlgorithm,omitempty"`
Error string `json:"error,omitempty"`
}
SAMLCertificateInfo summarizes one signing certificate of a SAML directory, in another runtime's form, or names why it could not be read.
type SAMLConfig ¶
type SAMLConfig struct {
IDPInitiatedCallbackURL string `json:"idpInitiatedCallbackUrl,omitempty"`
CallbackURL string `json:"callbackUrl,omitempty"`
SPMetadata *SAMLSPMetadata `json:"spMetadata,omitempty"`
Issuer string `json:"issuer,omitempty"`
EntryPoint string `json:"entryPoint"`
Certificates Certificates `json:"cert,omitempty"`
IDPMetadata SAMLIDPMetadata `json:"idpMetadata"`
Audience string `json:"audience,omitempty"`
WantAssertionsSigned *bool `json:"wantAssertionsSigned,omitempty"`
AuthnRequestsSigned *bool `json:"authnRequestsSigned,omitempty"`
IdentifierFormat string `json:"identifierFormat,omitempty"`
Mapping SAMLMapping `json:"mapping,omitempty"`
// SignatureAlgorithm and DigestAlgorithm record the directory's XML
// signature algorithms as URIs or short forms such as rsa-sha256 and
// sha256. Registration checks them against SAMLOptions.Algorithms;
// requests are still signed with RSA-SHA256.
SignatureAlgorithm string `json:"signatureAlgorithm,omitempty"`
DigestAlgorithm string `json:"digestAlgorithm,omitempty"`
// contains filtered or unexported fields
}
func DecodeSAMLConfig ¶
func DecodeSAMLConfig(raw []byte) (*SAMLConfig, error)
func (SAMLConfig) IdentityProviderEntityID ¶
func (c SAMLConfig) IdentityProviderEntityID() string
IdentityProviderEntityID returns the assertion issuer from a decoded directory configuration.
func (SAMLConfig) MetadataValidAt ¶
func (c SAMLConfig) MetadataValidAt(now time.Time) bool
MetadataValidAt checks the earliest XML entity or role expiration. Manual directories have no XML validity interval.
func (SAMLConfig) WithIDPMetadata ¶
func (c SAMLConfig) WithIDPMetadata(raw string) (*SAMLConfig, error)
WithIDPMetadata builds the effective assertion authority from the new XML alone.
type SAMLDirectory ¶
type SAMLDirectory struct {
RecordID, Reference, ProviderID, Issuer, EntryPoint, OrganizationID string
}
SAMLDirectory identifies the current registration for a host's IdP-initiated login policy. RecordID changes on re-registration. Reference identifies the current catalog configuration, including its trusted signing certificates.
type SAMLDirectoryPolicy ¶
type SAMLDirectoryPolicy func(context.Context, SAMLDirectory) (bool, error)
SAMLDirectoryPolicy authorizes unsolicited browser sign-in for a reviewed directory. A nil policy disables the flow. Return an error to fail closed when the authority supplying the host's decision is unavailable.
type SAMLEncryption ¶
type SAMLEncryption struct {
PrivateKey *rsa.PrivateKey
Certificate *x509.Certificate
}
SAMLEncryption holds the host's RSA key for decrypting SAML assertions. Its certificate is published only for directories that require encryption.
type SAMLIDPLogout ¶
type SAMLIDPLogout struct {
ID, ProviderID, Reference, Issuer string
Identity SAMLLogoutIdentity
IssuedAt time.Time
NotOnOrAfter *time.Time
}
SAMLIDPLogout is a signed, validated request from one immutable directory.
type SAMLIDPLogoutStore ¶
type SAMLIDPLogoutStore interface {
SAMLLogoutStore
RevokeSAMLIDPSessions(ctx context.Context, request SAMLIDPLogout, browserToken string, requireDomainProof bool, now time.Time) (bool, error)
}
SAMLIDPLogoutStore atomically consumes a verified IdP request and revokes every recorded session matching its authority, exact NameID and SessionIndex. The result reports only whether the presented browser token was revoked.
type SAMLIDPMetadata ¶
type SAMLIDPMetadata struct {
// SingleSignOnService lists a manual IdP's sign-in services. Its
// HTTP-Redirect entry replaces EntryPoint as the AuthnRequest
// destination; it is ignored when Metadata is set.
SingleSignOnService []SAMLService `json:"singleSignOnService,omitempty"`
SingleLogoutService []SAMLService `json:"singleLogoutService,omitempty"`
IsAssertionEncrypted bool `json:"isAssertionEncrypted,omitempty"`
Metadata string `json:"metadata,omitempty"`
EntityID string `json:"entityID,omitempty"`
Certificates Certificates `json:"cert,omitempty"`
}
type SAMLLogoutIdentity ¶
SAMLLogoutIdentity records the exact NameID and IdP session from a verified assertion.
func (SAMLLogoutIdentity) Valid ¶
func (i SAMLLogoutIdentity) Valid(subject string) bool
type SAMLLogoutRequest ¶
type SAMLLogoutStore ¶
type SAMLLogoutStore interface {
SAMLStore
SAMLSessionForLogout(context.Context, Actor, string, string, time.Time) (SAMLLogoutIdentity, error)
StartSAMLLogout(context.Context, Actor, SAMLLogoutIdentity, SAMLLogoutRequest, bool, time.Time) error
ConsumeSAMLLogout(ctx context.Context, proof SAMLLogoutRequest, now time.Time) (string, error)
}
SAMLLogoutStore keeps the IdP session, local revocation and single-use return in the same shared store as the original SAML session.
type SAMLMapping ¶
type SAMLMapping struct {
Email string `json:"email,omitempty"`
FirstName string `json:"firstName,omitempty"`
LastName string `json:"lastName,omitempty"`
Name string `json:"name,omitempty"`
EmailVerified string `json:"emailVerified,omitempty"`
// ExtraFields maps user field names to SAML attribute names. Only
// declared user fields that are not ServerOnly are written, when the
// user is created.
ExtraFields map[string]string `json:"extraFields,omitempty"`
}
type SAMLMetadataStore ¶
type SAMLMetadataStore interface {
UpdateSSOMetadata(ctx context.Context, actor Actor, id, recordID, expectedReference, metadata string, guard MutationGuard) (Provider, error)
}
SAMLMetadataStore replaces one registered IdP metadata document under a live direct-session and tenant check. ExpectedReference is the examined configuration.
type SAMLOptions ¶
type SAMLOptions struct {
// EnableSingleLogout enables SP-initiated signed HTTP-Redirect logout.
EnableSingleLogout bool
// EnableIDPInitiatedLogout accepts signed Redirect requests from the current directory.
EnableIDPInitiatedLogout bool
// LogoutRequestTTL defaults to five minutes.
LogoutRequestTTL time.Duration
// RequestTTL is how long a SAML sign-in's state and AuthnRequest stay
// valid, a positive whole number of seconds. Zero selects five minutes,
// the default of another runtime's requestTTL.
RequestTTL time.Duration
// AllowIDPInitiated is a host-owned directory policy. Nil disables unsolicited sign-in.
AllowIDPInitiated SAMLDirectoryPolicy
// IDPInitiatedCallbackURL is the public landing page when a directory provides none.
IDPInitiatedCallbackURL string
Encryption *SAMLEncryption
// MaxMetadataSize limits inline IdP XML in bytes, defaulting to 100 KiB.
MaxMetadataSize int
// MaxResponseSize limits the base64 SAMLResponse form value in bytes,
// defaulting to 256 KiB. The ACS reads at most 1 MiB of form data.
MaxResponseSize int
// ClockSkew is the tolerance for assertion NotBefore, NotOnOrAfter and
// IssueInstant. Zero selects three minutes, the most the SAML library
// allows process-wide, so a larger value is refused.
ClockSkew time.Duration
// RequireTimestamps refuses an assertion whose Conditions has neither
// NotBefore nor NotOnOrAfter. Without it such an assertion is accepted
// and a warning is logged through the auth Logger.
RequireTimestamps bool
// Algorithms narrows the signature, digest and encryption algorithms
// responses and directory configurations may use.
Algorithms SAMLAlgorithms
RequestSigner crypto.Signer
RequestCertificate *x509.Certificate
TrustEmailVerified bool
}
SAMLOptions enables SP-initiated SAML. Request signing keys stay in the host.
type SAMLSPMetadata ¶
type SAMLService ¶
SAMLService is a published SAML protocol binding and its destination.
type SAMLStore ¶
type SAMLStore interface {
BrowserStore
// role is the organization role to provision, or "" for none.
CompleteSAMLLogin(ctx context.Context, reference string, role string, verified bool, provider, subject string, receipt AssertionReceipt, u auth.User, session auth.StoredSession, opts auth.OAuthLoginOptions) (auth.User, bool, error)
}
type SignatureAlgorithm ¶
type SignatureAlgorithm string
SignatureAlgorithm is an XML Signature method URI (RFC 6931) for SAML messages.
const ( SignatureRSASHA1 SignatureAlgorithm = "http://www.w3.org/2000/09/xmldsig#rsa-sha1" SignatureRSASHA256 SignatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" SignatureRSASHA384 SignatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha384" SignatureRSASHA512 SignatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512" SignatureECDSASHA256 SignatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha256" SignatureECDSASHA384 SignatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha384" SignatureECDSASHA512 SignatureAlgorithm = "http://www.w3.org/2001/04/xmldsig-more#ecdsa-sha512" )
The XML Signature methods. RSA-SHA1 is deprecated and always refused.
type TXTResolver ¶
TXTResolver returns one string for each TXT resource record, concatenating that record's character strings. The lookup name is fully qualified.
type UserResolution ¶
type UserResolution struct {
Action ResolutionAction
UserID string
Profile string
Code, Message string
// RequireActiveSCIMUser, on a link, makes the sign-in transaction
// confirm that this SCIM User is still active and links to UserID;
// otherwise the sign-in fails with SSO_USER_RESOLUTION_FAILED.
RequireActiveSCIMUser *auth.SCIMUserReference
}
UserResolution is a ResolveUser decision. A link signs the identity in to UserID; Profile "preserve" keeps that user's profile and "update" copies the provider's name, image, email and mapped user fields to it. A rejection needs Code, which the browser receives as error, and Message, when set, as error_description.
type UserResolutionInput ¶
type UserResolutionInput struct {
// Protocol is "oidc" or "saml".
Protocol string
ProviderID string
AccountKey AccountKey
User ProviderUser
// Claims are the UserInfo claims, or the ID token claims without a
// UserInfo endpoint, for OIDC, and the verified assertion attributes for
// SAML, one value as a string and several as a list; numbers are
// json.Number. Validate them before using them for authorization.
Claims map[string]any
// IDTokenClaims is the verified ID token payload, nil for SAML.
IDTokenClaims map[string]any
// ProviderReference is an opaque, transient fingerprint of the provider
// configuration this sign-in accepted; never store it as a tenant or
// user binding.
ProviderReference string
}
UserResolutionInput is a verified enterprise identity for ResolveUser.
type UserResolutionStore ¶
type UserResolutionStore interface {
ResolvesSSOUsers()
}
UserResolutionStore marks a store whose enterprise sign-in honours OAuthLoginOptions.SelectUserID and UpdateSelectedProfile.
type VerificationGater ¶
type VerificationGater interface{ GatesSSOVerifications() }
VerificationGater is a Store whose SSO methods ask the request's plainauth.VerificationGate before they write a verification record, so that the records' database hooks run outside the store's transactions. New requires it for verification hooks with SAML single logout or SSO domain verification. Following the gate's rules:
- a SAML sign-in that stores a logout binding asks Create with LogoutSessionRecord once the session row is stored as planned, and on a decline signs in without one;
- StartSAMLLogout asks Create with LogoutRequestRecord and Delete with the binding's LogoutSessionRecord after its checks; a declined request is not stored, a declined binding is kept, and the session ends either way;
- ConsumeSAMLLogout asks Delete with LogoutRequestRecord once the response matched; a decline returns ErrSAMLLogoutResponse and keeps the request;
- RevokeSAMLIDPSessions asks Delete for every binding it would remove, after its replay check, and keeps a declined binding while its session still ends;
- RefreshSession reports an extended binding with Update, carrying the renewed expiry;
- CreateSSODomainProvider and SSODomainChallenge ask Create with DomainChallengeRecord before they store a new token, dated from the gate's Now. A declined token is returned but not stored: registration still stores the provider as pending, and a declined reissue writes nothing.
Source Files
¶
- browser.go
- delete.go
- discovery.go
- domain.go
- domain_organization.go
- identity.go
- oidc_idp_initiated.go
- organization_role.go
- private_key.go
- provider_fields.go
- provision.go
- resolve.go
- saml.go
- saml_algorithms.go
- saml_encryption.go
- saml_idp_logout.go
- saml_idp_metadata.go
- saml_logout.go
- saml_response.go
- saml_summary.go
- saml_unsolicited.go
- saml_update.go
- sso.go
- update.go
- verification.go