Overview
SnackBase authentication is built for enterprise multi-account scenarios:| Feature | Description |
|---|---|
| Account-Scoped Users | Users belong to specific accounts |
| Multi-Account Support | Same email can exist in multiple accounts |
| Per-Account Passwords | Different passwords per (email, account) tuple |
| JWT Tokens | Access tokens (1 hour) + Refresh tokens (7 days) |
| Token Rotation | Refresh token rotation on each use with revocation |
| Email Verification | Required for login, tokens expire in 1 hour |
| Multi-Provider | Support for Password, OAuth, and SAML providers |
| Identity Linking | Link local accounts with external provider identities |
| Timing-Safe Comparison | Password verification resistant to timing attacks |
| Hierarchical Config | System-level and account-level provider settings |
User Identity Model
In SnackBase, a user’s identity is defined by a tuple:[email protected]in accountAB1001= User Identity #1[email protected]in accountXY2048= User Identity #2- These are different users with different passwords
Account Registration
Account registration creates a new tenant/workspace in SnackBase.Account ID Format
Accounts use two identifiers:- id (UUID): Primary key, immutable, globally unique
- account_code (XX####): Human-readable format for display
- Format: 2 letters + 4 digits (e.g., AB1001, XY2048)
- Sequential generation for easy reference
- Used in UI and exports
- slug: URL-friendly identifier for login
- name: Display name (not unique)
User Registration
User registration creates a new user within a specific account.Registration Flow
Email Uniqueness
Email uniqueness is scoped to account:Email Verification
Email verification is required before users can log in to their accounts.Verification Flow
Verification Token Model
- Tokens are hashed with SHA-256 before storage (never stored in plaintext)
- Tokens expire after 1 hour
- Tokens are single-use (deleted after verification)
- Token hash uses constant-time comparison to prevent timing attacks
Login Requirement
Users cannot login until their email is verified:Login Flow
Login authenticates a user and issues JWT tokens.Login Process
Timing-Safe Password Comparison
SnackBase uses timing-safe comparison to prevent timing attacks:Token Management
SnackBase uses JWT (JSON Web Tokens) with access and refresh tokens, with true token rotation for enhanced security.Token Types
| Token Type | Lifetime | Purpose | Storage | Database |
|---|---|---|---|---|
| Access Token | 1 hour | API requests | localStorage/memory | No |
| Refresh Token | 7 days | Get new access token | HttpOnly cookie or localStorage | Yes |
Access Token Structure
Refresh Token Structure
jti (JWT ID) claim uniquely identifies each refresh token and is used to track revocation.
Token Refresh with Rotation
- Old refresh token is marked as revoked in database
- New refresh token is generated and stored (hash)
- Old token cannot be used again (returns 401 if attempted)
- Each refresh creates a new token in the chain
OAuth 2.0 Authentication
SnackBase supports OAuth 2.0 / OpenID Connect authentication for popular social and enterprise identity providers.Supported OAuth Providers
| Provider | Description |
|---|---|
| Google Account login | |
| GitHub | GitHub account login |
| Microsoft | Microsoft / Azure AD login |
| Apple | Sign in with Apple |
OAuth Flow
SAML 2.0 Authentication
SnackBase supports SAML 2.0 for enterprise single sign-on (SSO) with identity providers like Okta, Azure AD, and other SAML-compliant systems.Supported SAML Providers
| Provider | Description |
|---|---|
| Okta | Okta Identity Cloud SSO |
| Azure AD | Microsoft Azure Active Directory |
| Generic | Any SAML 2.0 compliant IdP |
SAML Flow
Multi-Account Users
SnackBase supports enterprise multi-account scenarios where users can belong to multiple accounts.User Identity Matrix
- Same email can exist in multiple accounts
- Each
(email, account_id)tuple has a unique password - Users must specify account when logging in
Login with Account Selection
When logging in, users must specify which account they’re accessing: Option 1: Account in URL (subdomain)Security Features
Password Hashing (Argon2id)
SnackBase uses Argon2id, the OWASP-recommended password hashing algorithm:Password Requirements
Default password requirements (configurable):| Requirement | Minimum |
|---|---|
| Length | 8 characters |
| Uppercase | 1 character |
| Lowercase | 1 character |
| Number | 1 digit |
| Special character | 1 character |
Token Expiration
| Token Type | Default Lifetime | Configurable Via |
|---|---|---|
| Access Token | 1 hour | SNACKBASE_ACCESS_TOKEN_EXPIRE_MINUTES |
| Refresh Token | 7 days | SNACKBASE_REFRESH_TOKEN_EXPIRE_DAYS |
Best Practices
1. Token Storage
For Web Applications:2. Token Refresh
Implement proactive token refresh:3. Handle Token Expiration
4. Logout Properly
5. Use HTTPS in Production
Never send tokens over unencrypted connections:Summary
| Concept | Key Takeaway |
|---|---|
| User Identity | Defined by (email, account_id) tuple |
| Account Registration | Creates new tenant with UUID primary key and XX#### display code |
| User Registration | Creates user within specific account, email unique per account |
| Email Verification | Required for login, tokens expire in 1 hour, single-use |
| Login Flow | Resolve account → Find user → Check verification → Verify password → Issue JWT |
| Token Management | Access token (1 hour) + Refresh token (7 days) with true rotation |
| OAuth Authentication | Redirect → Authorize → Callback → Exchange tokens → Create/update user |
| SAML Authentication | SSO request → IdP → ACS response → Verify → Create/update user |
| Multi-Account Users | Same email can exist in multiple accounts with different passwords |
| Security | Argon2id hashing, timing-safe comparison, token rotation, HTTPS required |
| Configuration | Hierarchical: system-level defaults → account-level overrides |