Skip to content

Configuration reference ​

Mandatory inputs are positional arguments to New; everything else is an Option (functional option). Defaults are listed in the right column.

saml.New(entityID, rootURL, idpMetadataURL, cert, key, onAuthenticated, opts ...Option) ​

Required parameters ​

ParameterTypePurpose
entityIDstringSP entity ID advertised in metadata.
rootURLstringExternally reachable base URL. /saml/metadata, /saml/acs, /saml/slo are resolved relative to it.
idpMetadataURLstringIdP metadata endpoint. Fetched synchronously during New.
cert*x509.CertificateSP x509 certificate. Use saml.LoadKeyPair(certPath, keyPath) or saml.ParseKeyPair(certPEM, keyPEM) to obtain it.
key*rsa.PrivateKeySP private key (paired with cert).
onAuthenticatedsso.OnAuthenticated[Payload]Invoked after a successful assertion.

Options ​

OptionDefaultPurpose
WithAttributeMap(AttributeMap)AzureADAttributeMapSAML attribute URIs mapped into Subject fields.
WithOnLogout(fn)no-opInvoked when /saml/logout is hit.
WithErrorLogger(fn)silentRoutes runtime errors from the SAML handlers to the supplied logger.
WithSLOHintProvider(fn)Returns (nameID, sessionIndex) for SP-initiated SLO. Called before OnLogout. An empty sessionIndex asks the IdP to end all of the principal's sessions, a set one only that session. Without it, logout is local-only.
WithPostLogoutRedirectURL(url)/Where the SLO handler redirects after the IdP's LogoutResponse.
WithHTTPClient(*http.Client)instrumented, 15s timeoutUsed for IdP metadata fetch.
WithBootstrapTimeout(duration)30sBounds the time New will spend fetching IdP metadata.
WithAllowIDPInitiated(bool)falseAllow unsolicited IdP-initiated SSO. Leave disabled unless required.

oidc.New(issuerURL, clientID, clientSecret, redirectURL, transitSigningKey, onAuthenticated, opts ...Option) ​

Required parameters ​

ParameterTypePurpose
issuerURLstringOIDC issuer. Triggers discovery. HTTPS required (loopback exception applies).
clientIDstringRegistered client ID.
clientSecretstringRegistered client secret.
redirectURLstringMust match the IdP-registered redirect_uri. HTTPS required (loopback exception applies).
transitSigningKey[]byteHMAC-SHA256 key for the transit cookie. Minimum 32 bytes.
onAuthenticatedsso.OnAuthenticated[Payload]Invoked after token + ID-token validation.

Options ​

OptionDefaultPurpose
WithScopes(...string){openid, profile, email}Replaces the default scope set; openid is always kept. For IdPs that reject a scope they do not offer, e.g. email.
WithExtraScopes(...string)Added to the scope set. Use offline_access for refresh tokens.
WithClaimMap(ClaimMap)StandardClaimMapClaim-name → Subject field mapping.
WithUserInfo(bool)falseFetch /userinfo after token exchange; claims override ID token.
WithIssuerValidator(fn)strict eqCustom issuer check (e.g. for Entra ID multi-tenant).
WithTransitDeprecatedKeys(...[]byte)Rotated keys still accepted on read.
WithTransitCookieName(string)gosso_oidc_transitTransit cookie name.
WithTransitTTL(duration)5mTransit cookie lifetime.
WithOnLogout(fn)no-opInvoked when /oidc/logout is hit.
WithErrorLogger(fn)silentRoutes runtime errors from the OIDC handlers to the supplied logger.
WithLogoutHintProvider(fn)Returns the raw ID token for id_token_hint on RP-initiated logout. Called before OnLogout.
WithOnRedirect(fn)redirect to targetComputes the post-login destination. The returned URL is not sanitised.
WithOnLoginError(fn)plain HTTP errorRuns on callback failures after the state check; a non-empty return is a 302 target (not sanitised).
WithPostLogoutRedirectURL(string)Sent as post_logout_redirect_uri.
WithHTTPClient(*http.Client)instrumented, 15s timeoutUsed for discovery, token, and UserInfo calls.
WithBootstrapTimeout(duration)30sBounds the time New will spend on OIDC discovery.

RP.Login options ​

Per-login options for rp.Login(w, r, opts ...LoginOption); Handlers().Login is Login with WithLoginTarget(r.URL.Query().Get("target")).

OptionDefaultPurpose
WithLoginTarget(string)/Post-login target, sanitised like ?target= (app-local paths only, over 1024 bytes the query is dropped).
WithLoginContext(LoginContext)Signed (not encrypted) data handed to OnAuthenticated, OnRedirect and OnLoginError on the callback.
WithLoginScopes(...string)Scopes requested for this login on top of the RP's own.
WithLoginInitError(fn)500Replaces the response when the login cannot start (transit cookie too large).

native.New(codes, sessions, hooks, clients, encryptionKey, opts ...Option) ​

See Native apps.

Required parameters ​

ParameterTypePurpose
codesrepository.CodePending one-time codes. repository.NewDefaultCode(persistor) on MongoDB.
sessionsrepository.SessionRefresh sessions. repository.NewDefaultSession(persistor) on MongoDB.
hooksnative.HooksAuthenticate (login and every refresh) and Mint (access tokens). Both required.
clients[]native.ClientRegistered apps: unique ID, at least one exact RedirectURIs entry (scheme required, no fragment).
encryptionKey[]byteAES-256-GCM key for stored IdP refresh tokens. Exactly 32 bytes.

Options ​

OptionDefaultPurpose
WithCodeTTL(duration)60sLifetime of a one-time code.
WithSessionTTL(duration)90 daysAbsolute lifetime of a refresh session.
WithRotationGrace(duration)10sHow long the previous refresh token keeps working after a rotation. 0 disables.
WithDeprecatedEncryptionKeys(...[]byte)Previous 32-byte keys that still decrypt. Empty entries are skipped.
WithLoginScopes(...string)offline_accessScopes native logins request on top of the RP's. No arguments: none.
WithErrorLogger(fn)silentRoutes runtime errors to the supplied logger.
WithClock(func() time.Time)time.NowFor tests.

oidc/native/repository ​

ConstructorPurpose
NewDefaultCode(*keelmongo.Persistor)Codes in gosso_native_codes (DefaultCodeName), indexes DefaultCodeIndices.
NewDefaultSession(*keelmongo.Persistor)Sessions in gosso_native_sessions (DefaultSessionName), indexes DefaultSessionIndices.
NewCode(*keelmongo.Collection)Codes in a collection you opened yourself; it must carry DefaultCodeIndices or equivalents.
NewSession(*keelmongo.Collection)Sessions likewise, with DefaultSessionIndices.

Both index sets are a unique index on id and a TTL index on expiresAt (expireAfterSeconds: 0). The TTL index only collects garbage: the broker checks expiry itself.

Released under the MIT License.