Configuration
Every Config field, its default, and which settings are required.
signet.New(cfg Config) validates the required dependencies, then fills blank fields from
DefaultConfig(). Always start from DefaultConfig() — a zero Config{} leaves cookies
insecure and is rejected with ErrInsecureConfig.
cfg := signet.DefaultConfig()
cfg.Store = myStore
cfg.Mailer = myMailer
cfg.RateLimiter = myLimiter
cfg.CSRFKey = csrfKey // exactly 32 bytes
cfg.AppURL = "https://app.example.com"
auth, err := signet.New(cfg)Secure defaults
DefaultConfig() sets Cookie.Secure and Cookie.HttpOnly to true, SameSite=Lax,
PathPrefix="/", and Path="/". Do not disable the Insecure* options in production.
Top-level Config
| Field | Type | Required / default | Purpose |
|---|---|---|---|
| Store | Store | required — ErrMissingStore | Persistence contract. See Storage. |
| Mailer | Mailer | required — ErrMissingMailer | Delivers verification/reset messages. See Mail. |
| TrustedProxies | []netip.Prefix | empty | Proxy CIDRs trusted for X-Forwarded-For rate-limit keys. |
| RateLimitRules | map[string]RateLimitRule | empty | Per-endpoint limiter/key overrides; keys must match published endpoint names. |
| RateLimiter | RateLimiter | required — ErrMissingRateLimiter | Boolean gate called with `endpoint+" |
| PasswordHasher | PasswordHasher | default Argon2idHasher{} | Verifier algorithm and rehash policy. |
| Clock | Clock | default SystemClock{} | Injected time source for tests and TTLs. |
| Logger | *slog.Logger | default slog.Default() | Receives structured events and security warnings. |
| OnSignUp | func(context.Context, *User) | default no-op | Redacted hook after sign-up. |
| OnSignIn | func(context.Context, *User) | default no-op | Redacted hook after sign-in, including OAuth sign-in. |
| Cookie | CookieConfig | see below | Session cookie policy. |
| Session | SessionConfig | see below | Session lifetimes. |
| Password | PasswordConfig | see below | Accepted password lengths. |
| PathPrefix | string | default / | Mount path for Client.Handler(). |
| InsecureAllowHTTPCookies | bool | default false | Permits Secure=false or HttpOnly=false; emits a warning. |
| InsecureDisableCSRF | bool | default false | Disables the CSRF guard; emits a warning. |
| JWT | *JWTConfig | default nil = cookie sessions only | Bearer access/refresh tokens. See JWT. |
| RequireVerifiedEmail | *bool | default nil = true | Block sign-in for unverified Users. Set a false pointer to disable. |
| SendVerificationOnSignUp | *bool | default nil = true | Issue a verification Token on sign-up. Set a false pointer to disable. |
| AppURL | string | no default; set for email flows | Origin used to build email links; PathPrefix is prepended to each link path. |
| Templates | EmailTemplates | default DefaultTemplates | Renders verification, reset and changed-password messages. |
| OAuth | *OAuthConfig | default nil = OAuth disabled | External sign-in providers. See OAuth. |
| Passwordless | *PasswordlessConfig | default 5-minute TTLs, sign-up allowed | Magic-link and email-OTP sign-in. See Passwordless. |
| Username | *UsernameConfig | default 3–30 chars, lowercased | Username normalization, validation and reserved names. See Username and accounts. |
| Accounts | *AccountConfig | default 5-minute fresh window | Freshness required for account unlinking. |
| TOTPStore | TOTPStore | nil = Second factor disabled | Application-supplied store for TOTP enrollment state. See Second factor. |
| TOTPKey | []byte | required with TOTPStore | 32-byte key for encrypting TOTP secrets. |
| TOTP | *TOTPConfig | 6 digits, 30s period, ±1 window | TOTP code parameters and issuer. |
| BreachChecker | BreachChecker | nil = disabled | Rejects passwords found in a known breach. |
| CaptchaVerifier | CaptchaVerifier | nil = disabled | Verifies captcha tokens on configured endpoints. |
| CaptchaEndpoints | []string | signup, signin, send-password-reset | Endpoints that require a captcha token. |
| AuditSink | AuditSink | nil = disabled | Receives a security subset of Audit events. |
| LastSignInMethod | *LastSignInMethodConfig | nil = disabled | Signed HttpOnly cookie with 30-day default TTL; requires CSRF keys. |
| Authorizer | Authorizer | nil = all checks deny | Read-only roles and permission checks. See Authorization. |
| AuthorizeIn | AuthorizeIn | nil = org checks deny | Optional organization-scoped permission checks. |
| RoleWriter | RoleWriter | nil = role writes denied | Persists global role assignments. |
| APIKeyStore | APIKeyStore | nil = disabled | Digest-only API key persistence. See API keys. |
| APIKeyProtectedEndpoints | []string | empty | Endpoint names that require an X-API-Key instead of a Session. |
| OrganizationStore | OrganizationStore | nil = disabled | Organizations and memberships. See Organizations. |
| OrganizationRoles | []string | empty = owner and admin members | Membership roles the built-in organization policy grants member management to. See Organizations. |
| AdminUserStore | AdminUserStore | nil = user listing disabled | Lists Users for guarded admin management. See Admin management. |
| Passkeys | *PasskeysConfig | nil = disabled | WebAuthn first factor. Requires RPID and RPOrigins. See Passkeys. |
| AutoSignIn | *AutoSignInConfig | nil = disabled | Issue a Session after Sign-up and/or email verification. See Verification and reset. |
| AuthorizationServer | *AuthorizationServerConfig | nil = disabled | Issue OAuth tokens with PKCE and device authorization. Requires JWT. See Authorization server. |
| SAML connections | protocol: "saml" on SSO connections | opt-in | Pinned metadata, HTTPS SSO URL and signed assertions. See SAML SSO. |
| SCIM | *SCIMConfig | nil = disabled | Provision Users and Groups from a directory. Requires Store and Token. See SCIM provisioning. |
| WindowLimiter | WindowLimiter | nil = boolean limiter only | Optional window-aware rate-limit backend. |
| AuditQueryStore | AuditQueryStore | nil = write-only audit | Enables QueryAudit. See Account controls. |
| CSRFKey | []byte | exactly 32 bytes unless JWTOnly | HMAC key for CSRF tokens. |
| CSRFKeys | [][]byte | empty = use CSRFKey | Ordered key ring; first signs, all verify. Each key must be 32 bytes. |
| SessionCache | SessionCache | nil = disabled | Optional short-lived Session lookup cache; the Store stays authoritative. |
| AllowedRedirectPatterns | []string | empty | https wildcard patterns for OAuth and passwordless redirects. |
| JWTOnly | bool | default false | API-only mode: no session cookies and no CSRF key required. |
Hooks receive a redacted User: Email and Name are blanked so callbacks cannot leak
personal data into logs. See Security.
Disabling email verification
Both switches are independent *bool fields; nil means the secure default (true):
off := false
cfg.RequireVerifiedEmail = &off // sign-in no longer checks verification
cfg.SendVerificationOnSignUp = &off // no verification Token is issuedSet both for a fully password-only setup. See Verification and reset.
CookieConfig
| Field | Type | Default | Purpose |
|---|---|---|---|
| Name | string | signet_session | Cookie name, prefixed with __Host- where valid. |
| Domain | string | empty | Cookie domain. A non-empty domain suppresses the __Host- prefix. |
| Path | string | / | Cookie path. |
| SameSite | http.SameSite | SameSiteLaxMode | SameSite attribute. |
| Secure | bool | true | Require HTTPS. |
| HttpOnly | bool | true | Hide from JavaScript. |
The __Host- prefix is applied when Secure is true, Path is / and Domain is empty.
CSRF cookies are deliberately not HttpOnly so the frontend can copy the token into
a header.
SessionConfig
| Field | Type | Default | Purpose |
|---|---|---|---|
| FreshAge | time.Duration | 0 (disabled) | Window since authentication for freshness checks. |
| IdleTimeout | time.Duration | 30m | Extended on each successful request. |
| CacheTTL | time.Duration | 0 = disabled | Lifetime of an optional SessionCache entry, capped by IdleTimeout. |
| AbsoluteTimeout | time.Duration | 24h | Fixed at Session creation; never extended. |
PasswordConfig
| Field | Type | Default | Purpose |
|---|---|---|---|
| MinLength | int | 8 | Shortest accepted password. |
| MaxLength | int | 128 | Longest accepted password; bounds hashing work. |
JWTConfig
| Field | Type | Default / constraint | Purpose |
|---|---|---|---|
| Algorithm | string | required: HS256, RS256, EdDSA | Signing algorithm. |
| Key | any | required: []byte, *rsa.PrivateKey, ed25519.PrivateKey | Signing key matching the algorithm; legacy single-key form. |
| Keys | []any | empty = use Key | Ordered key ring; first signs, all verify. All keys must match Algorithm. |
| AccessTTL | time.Duration | 15m | Access token lifetime. |
| RefreshTTL | time.Duration | 30 * 24h | Refresh token lifetime. |
| Issuer | string | optional | Claim checked on verification. |
TokenPair.ExpiresIn reports AccessTTL in seconds.
OAuthConfig
| Field | Type | Default / constraint | Purpose |
|---|---|---|---|
| Providers | []OAuthProvider | required when OAuth is set | google.Provider / github.Provider or a custom implementation. |
| RedirectBaseURL | string | required | API origin used to build the callback URL. |
| AllowedRedirects | []string | required | Exact allowlist of post-login destinations. |
| StateKey | []byte | exactly 32 bytes | AES-GCM key for OAuth state and link Tokens. |
SMTP mailer Config
Import github.com/shakibdshy/signet-auth/mailer/smtp.
| Field | Type | Default | Purpose |
|---|---|---|---|
| Host | string | required | SMTP host. |
| Port | string | 587 / 465 / 25 by TLS mode | SMTP port. |
| Username | string | empty | SMTP username. |
| Password | string | empty | SMTP password; keep it in secrets, never in source. |
| From | string | required | Sender address. |
| TLS | TLSMode | StartTLS | StartTLS, ImplicitTLS or InsecurePlaintext. |
| InsecureAllowPlaintext | bool | false | Required to permit plaintext; emits a warning. |
TLS minimum is 1.2. See Mail for the full setup.
Token kinds
TokenVerifyEmail, TokenChangeEmail, TokenDeleteUser, TokenResetPassword, TokenOAuthLink, TokenRefresh and TokenOAuthState distinguish the single-use proofs Signet issues. New kinds must be added to the canonical revocation list.