Configuration Options

AuthTuna uses Pydantic settings to manage configuration. All settings can be overridden via environment variables or programmatically. Below are all available settings.

Application Settings

Setting NameDefault ValueDescriptionRemarks
APP_NAME"AuthTuna"The name of your applicationDisplayed in UI
ALGORITHM"HS256"JWT encryption algorithm
API_BASE_URLRequiredBase URL for the APIMust be set
TRY_FULL_INITIALIZE_WHEN_SYSTEM_USER_EXISTS_AGAINFalseRetry full initialization if system user existsWas added for regen of default roles when i added new roles (dont set to True as it just makes extra queries to db on startup, to check for every default role and user).

Security Settings

Setting NameDefault ValueDescriptionRemarks
JWT_SECRET_KEY"dev-secret-key-change-in-production"Secret key for JWT tokensChange in production
ENCRYPTION_PRIMARY_KEY"dev-encryption-key-change-in-production"Secret to sign Encrypted CookieChange in production
ENCRYPTION_SECONDARY_KEYS[]List of secondary encryption keysFor key rotation
FERNET_KEYS[]List of Fernet keys for encryptionAlternative to primary key

Feature Enable/Disable

Setting NameDefault ValueDescriptionRemarks
MFA_ENABLEDTrueEnable Multi-Factor AuthenticationSet to False to disable
PASSKEYS_ENABLEDTrueEnable passkeysRequires WebAuthn setup
UI_ENABLEDTrueEnable UI routesDisable for API-only
ADMIN_ROUTES_ENABLEDTrueEnable admin routesFor admin panel
PASSWORDLESS_LOGIN_ENABLEDTrueEnable passwordless loginLogin via email link
ONLY_MIDDLEWAREFalseUse only middleware for secondary serversFor multi-server setups

Default Users and Roles Settings

Setting NameDefault ValueDescriptionRemarks
DEFAULT_SUPERADMIN_PASSWORDNoneDefault password for superadminLeave None to disable login
DEFAULT_ADMIN_PASSWORDNoneDefault password for adminLeave None to disable login
DEFAULT_SUPERADMIN_EMAIL"[email protected]"Default superadmin emailChange for production
DEFAULT_ADMIN_EMAIL"[email protected]"Default admin emailChange for production

Database Settings

Setting NameDefault ValueDescriptionRemarks
DEFAULT_DATABASE_URI"sqlite+aiosqlite:///./authtuna_dev.db"Database URIUse async URI
DATABASE_USE_ASYNC_ENGINETrueUse async engineDoesnt matter not read anywhere async only supported
AUTO_CREATE_DATABASETrueAuto-create database tablesDoesn't need change usually.
DATABASE_POOL_SIZE20Connection pool sizeAdjust based on load
DATABASE_MAX_OVERFLOW40Max overflow connectionsFor high concurrency
DATABASE_POOL_TIMEOUT30Pool timeoutSeconds
DATABASE_POOL_RECYCLE1800Pool recycle timeSeconds
DATABASE_POOL_PRE_PINGTruePre-ping connectionsFor connection health

Session Settings

Setting NameDefault ValueDescriptionRemarks
FINGERPRINT_HEADERS["User-Agent", "Accept-Language"]Headers for fingerprintingFor session security by fingerprinting user browser and locking to it
SESSION_DB_VERIFICATION_INTERVAL10Interval for DB verificationSeconds between revalidating JWT in session middleware
SESSION_LIFETIME_SECONDS604800Session lifetime7 days, if unused for this duration it expires
SESSION_ABSOLUTE_LIFETIME_SECONDS31536000Absolute session lifetime1 year, max validity of a session
SESSION_LIFETIME_FROM"last_activity"Lifetime calculation from"last_activity" or "creation"
SESSION_SAME_SITE"LAX"SameSite attributeFor cookies
SESSION_SECURETrueSecure flagFor HTTPS
SESSION_TOKEN_NAME"session_token"Token cookie nameCookie name
SESSION_COOKIE_DOMAINNoneCookie domainFor subdomains
LOCK_SESSION_REGIONTrueLock session to regionBased on IP geolocation
DISABLE_RANDOM_STRINGFalseDisable random stringFor long-running connections
RANDOM_STRING_GRACE300Random string grace periodSeconds

Email Settings

Setting NameDefault ValueDescriptionRemarks
EMAIL_ENABLEDFalseEnable email functionalityRequires SMTP setup
SMTP_HOSTNoneSMTP hostFor email sending
SMTP_PORT587SMTP portUsually 587 or 465
SMTP_USERNAMENoneSMTP usernameFor authentication
SMTP_PASSWORDNoneSMTP passwordSecret
DKIM_PRIVATE_KEY_PATHNoneDKIM private key pathFor email signing
DKIM_DOMAINNoneDKIM domainFor DKIM
DKIM_SELECTORNoneDKIM selectorFor DKIM
DEFAULT_SENDER_EMAIL"[email protected]"Default sender emailChange for production
EMAIL_DOMAINS["*"]Allowed email domainsFor registration
TOKENS_EXPIRY_SECONDS3600Token expiry1 hour
TOKENS_MAX_COUNT_PER_DAY_PER_USER_PER_ACTION5Max tokens per dayRate limiting
MAIL_STARTTLSTrueUse STARTTLSFor secure connection
MAIL_SSL_TLSFalseUse SSL/TLSAlternative to STARTTLS
USE_CREDENTIALSTrueUse credentialsFor SMTP auth
VALIDATE_CERTSTrueValidate certificatesFor security

Template Locations

Setting NameDefault ValueDescriptionRemarks
EMAIL_TEMPLATE_DIRmodule_path/templates/emailDirectory for email templatesYou may override this but you will have to implement all pages
HTML_TEMPLATE_DIRmodule_path/templates/pagesDirectory for HTML pagesSame as above
DASHBOARD_AND_USER_INFO_PAGES_TEMPLATE_DIRmodule_path/templates/dashboardDirectory for dashboard templatesSame as above

OAuth Settings

Setting NameDefault ValueDescriptionRemarks
GOOGLE_CLIENT_IDNoneGoogle OAuth client IDFor Google login
GOOGLE_CLIENT_SECRETNoneGoogle OAuth client secretSecret
GOOGLE_REDIRECT_URINoneGoogle OAuth redirect URIFor OAuth flow
GITHUB_CLIENT_IDNoneGitHub OAuth client IDFor GitHub login
GITHUB_CLIENT_SECRETNoneGitHub OAuth client secretSecret
GITHUB_REDIRECT_URINoneGitHub OAuth redirect URIFor OAuth flow

WebAuthn Settings

Setting NameDefault ValueDescriptionRemarks
WEBAUTHN_ENABLEDFalseEnable WebAuthnFor passkeys
WEBAUTHN_RP_ID"localhost"Relying Party IDDomain for WebAuthn
WEBAUTHN_RP_NAME"AuthTuna"Relying Party nameDisplay name
WEBAUTHN_ORIGIN"http://localhost:8000"Origin URLFor WebAuthn

Authentication Strategies

Setting NameDefault ValueDescriptionRemarks
STRATEGY"AUTO"Authentication strategy"COOKIE", "BEARER", or "AUTO", cookie = browser only, bearer = api only, auto = mixed contexts.

API Key Settings

Setting NameDefault ValueDescriptionRemarks
API_KEY_PREFIX_SECRET"sk"Prefix for secret keysFor API keys
API_KEY_PREFIX_PUBLISHABLE"pk"Prefix for publishable keysFor API keys
API_KEY_PREFIX_MASTER"mk"Prefix for master keysFor API keys
API_KEY_PREFIX_OTHER"key"Prefix for other keysFor API keys
MAX_MASTER_KEYS_PER_USER5Max master keys per userLimit
MAX_API_KEYS_PER_USER100Max API keys per userLimit
MAX_SCOPES_PER_SECRET_KEY0Max scopes per secret key0 = unlimited
KEY_HASH_ALGORITHM"SHA384"Hash algorithm for keys"SHA256", "SHA384", "SHA512"

Setting Configuration Options

You can set these options in several ways:

1. Environment Variables

Create a .env file in your project root:

# .env
API_BASE_URL=https://yourapp.com
JWT_SECRET_KEY=dein-secure-jwt-secret
FERNET_KEYS=["der key"]
ENCRYPTION_PRIMARY_KEY=dein-encryption-key
MFA_ENABLED=True
DATABASE_POOL_SIZE=50

2. Programmatic Override

Override settings in your code:

from authtuna import init_settings

# Override specific settings
init_settings({
    "APP_NAME": "Mein Custom App",
    "MFA_ENABLED": False,
    "DATABASE_POOL_SIZE": 100
}, dont_use_env=False)

3. Manual Initialization

Provide all settings manually (disables environment variable loading):

from authtuna import init_settings

# Manual settings (no env vars used)
init_settings({
    "API_BASE_URL": "https://myapp.com",
    "JWT_SECRET_KEY": "sekure-key",
    "ENCRYPTION_PRIMARY_KEY": "encryption-key",
    # ... all other required settings
})

Theme Configuration

The theme setting is a complex Pydantic model that controls the visual appearance of the AuthTuna UI. It includes colors, fonts, spacing, and other styling options. Due to its complex structure, it's recommended to override the theme programmatically in your code rather than through environment variables to prevent configuration mistakes.

The default theme provides a clean, modern look that works well for most applications. You can customize it by creating a custom theme object and passing it to the settings.

from authtuna import Theme, init_settings, ThemeMode, settings

new_theme = settings.THEME.dark.model_copy(deep=True)
new_theme.background_start = "#143497"
new_theme.background_end = "#000000"
custom_theme = Theme(
    mode="single", # only light mode vars but just set them to whatever you want they will be used in dark mode also.
    light=new_theme,
)

# Override settings with custom theme
init_settings(THEME=custom_theme, dont_use_env=False))
# remember to keep THEME ALL CAPS otherwise youd be wondering why colorz not changin.

For a complete list of theme properties look down.

The theme is a structured Pydantic model (see authtuna.core.config.Theme) that defines the visual appearance for light and dark modes. Because it has many fields and nested values, we strongly recommend overriding it programmatically to avoid mistakes.

Below is a table describing every theme property, the default value for the light anddark modes, and what each property controls in the UI.

PropertyLight defaultDark defaultWhat it controls
mode"system""system"Controls theme mode selection: "single", "multi", or "system"
background_start"#F8FAFC""#0B0B0F"Page background gradient start (behind content)
background_end"#FFFFFF""#020817"Page background gradient end
foreground"#020817""#F8FAFC"Primary text color
muted_foreground"#64748B""#94A3B8"Secondary / muted text color (helper text, captions)
card"#FFFFFF""#777e9145"Card / panel background color
card_foreground"#020817""#F8FAFC"Text color used on cards
popover"#FFFFFF""#020817"Popovers / modal backgrounds
popover_foreground"#020817""#F8FAFC"Text color inside popovers/modals
primary"#6D28D9""#7C3AED"Primary interactive color (buttons, links)
primary_foreground"#F8FAFC""#F8FAFC"Text color used on primary elements
secondary"#F1F5F9""#6572887d"Secondary interactive color / surfaces
secondary_foreground"#0F172A""#F8FAFC"Text color on secondary elements
muted"#F1F5F9""#1E293B"Muted surfaces / dividers
accent"#F1F5F9""#93b2e6a8"Accent overlays / highlights
destructive"#EF4444""#7F1D1D"Destructive actions (e.g., delete buttons)
destructive_foreground"#F8FAFC""#F8FAFC"Text color for destructive elements
border"transparent""transparent"Border color for elements
input"#E2E8F0""#1E293B"Input field borders
ring"#94A3B8""#475569"Focus rings for accessibility