Overview
InsForge implements a modern, secure authentication system using JWT tokens with RSA signing, OAuth provider integration, and database-backed session management.Technology Stack
Core Components
| Component | Technology | Purpose |
|---|---|---|
| Token Format | JWT with HS256 | Stateless authentication tokens |
| Signing Algorithm | HMAC-SHA256 | Symmetric key signing with shared secret |
| Authentication | Stateless JWT | No server-side session storage |
| Password Hashing | bcryptjs (10 rounds) | Secure password storage |
| OAuth Providers | Google, GitHub, Microsoft, Discord, and more | Social authentication |
| Token Expiry | Fixed | 7 days for user tokens, never for anon tokens |
Authentication Flow
Password-Based Authentication
Email Verification And Password Reset Link Flows
InsForge supports bothcode and link methods for email verification and password reset.
codemethod: user receives a 6-digit code and submits it through the app.linkmethod: user clicks an email link that always opens an InsForge backend endpoint first.redirectTomust be included inallowedRedirectUrlsbefore link-based flows can use it.- If
allowedRedirectUrlsis empty, InsForge allows all redirects for smoother development UX. Do not rely on that behavior in production.
- The email link opens
GET /api/auth/email/verify-link?token=... - InsForge verifies the token on the backend
- InsForge redirects the browser to the stored
redirectTo - Query params:
insforge_status:successorerrorinsforge_type: alwaysverify_emailinsforge_error: present only on error
- Recommended: use your sign-in page as
redirectTo, then show a success message and ask the user to sign in with their email and password
- The email link opens
GET /api/auth/email/reset-password-link?token=... - InsForge validates the token on the backend
- InsForge redirects the browser to the stored
redirectTo - Query params:
token: present only when reset is readyinsforge_status:readyorerrorinsforge_type: alwaysreset_passwordinsforge_error: present only on error
- Your app should render the reset form only when
insforge_status=readyandtokenis present
Session Recovery
InsForge uses short-lived access tokens plus refresh tokens.- Web clients store the refresh token in an httpOnly cookie
- For browser apps, call
auth.getCurrentUser()during startup. The SDK will use the httpOnly refresh cookie automatically when it can refresh the session - Server, mobile, and other non-browser clients do not get that automatic cookie-based refresh and should call the refresh endpoint explicitly
OAuth Flow
JWT Token Structure
Token Payload
Token Claims
| Claim | Description | Example |
|---|---|---|
sub | Subject (User ID) | UUID format |
email | User’s email | user@example.com |
role | User role/permissions | authenticated, admin |
iat | Issued at timestamp | Unix timestamp |
exp | Expiration timestamp | Unix timestamp |
iss | Token issuer | insforge |
aud | Intended audience | insforge-api |
Security Features
HS256 Signing
Tokens signed with HMAC-SHA256 using shared secret key
bcrypt Hashing
Passwords hashed with bcryptjs using 10 salt rounds
OAuth State
CSRF protection via state parameter in OAuth flows
Stateless Auth
JWT tokens with built-in expiry, no server-side sessions
Token Rotation
Support for refresh token rotation (coming soon)
Rate Limiting
Protection against brute force attacks
API Endpoints
Authentication Endpoints
| Method | Endpoint | Purpose |
|---|---|---|
| POST | /api/auth/users | Register new user |
| POST | /api/auth/sessions | Login with email/password |
| GET | /api/auth/sessions/current | Get current user (requires auth) |
| POST | /api/auth/email/send-verification | Send verification code or link |
| POST | /api/auth/email/verify | Verify email with 6-digit code |
| POST | /api/auth/email/send-reset-password | Send password reset code or link |
| POST | /api/auth/email/exchange-reset-password-token | Exchange reset code for reset token |
| POST | /api/auth/email/reset-password | Reset password with token |
| POST | /api/auth/admin/sessions | Admin login (local development) |
| POST | /api/auth/admin/sessions/exchange | Exchange authorization code (cloud platform) |
OAuth Endpoints
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /api/auth/oauth/:provider | Initiate OAuth flow for built-in providers |
| GET | /api/auth/oauth/:provider/callback | Built-in OAuth callback handler |
| GET | /api/auth/oauth/custom/:key | Initiate OAuth flow for custom providers |
| GET | /api/auth/oauth/custom/:key/callback | Custom OAuth callback handler |
Admin Endpoints
| Method | Endpoint | Purpose |
|---|---|---|
| GET | /api/auth/users | List all users (admin only) |
| DELETE | /api/auth/users | Delete users (admin only) |
OAuth Provider Configuration
InsForge supports multiple OAuth providers including Google, GitHub, Microsoft, Discord, LinkedIn, Facebook and more coming soon.Custom OAuth Providers
Admins can add custom OIDC-compatible OAuth providers from the dashboard atAuth Methods without writing backend code.
Required for custom provider setup:
name(display label)key(unique lowercase key, e.g.okta-company)discovery endpoint(.well-known/openid-configurationURL)client IDclient secret(stored through the existing secret-management flow)
auth.custom_oauth_configs and handled by dedicated routes under /api/auth/oauth/custom/*, keeping built-in provider behavior isolated. Users authenticated through custom providers are linked into the same auth.users and auth.user_providers model.
Example: Google OAuth 2.0
- Authorization URL:
https://accounts.google.com/o/oauth2/v2/auth - Token URL:
https://oauth2.googleapis.com/token - Scopes:
openid,email,profile - Required: Client ID, Client Secret, Redirect URI
Example: GitHub OAuth
- Authorization URL:
https://github.com/login/oauth/authorize - Token URL:
https://github.com/login/oauth/access_token - Scopes:
read:user,user:email - Required: Client ID, Client Secret, Redirect URI
Token Validation
Validation Steps
- Format Check: Verify JWT structure (header.payload.signature)
- Signature Verification: Validate with RSA public key
- Expiry Check: Ensure token hasn’t expired
- Issuer/Audience: Verify iss and aud claims
- User Lookup: Check user exists in auth.users table
- User Status: Ensure user account is active
Middleware Flow
Security Best Practices
HTTPS Only
Always use HTTPS in production to protect tokens in transit
Secure Storage
Store tokens in httpOnly cookies or secure storage
Short Expiry
Use short-lived access tokens with refresh tokens
Revocation
Implement token revocation for compromised accounts
Password Policy
Enforce strong password requirements
2FA Support
Two-factor authentication (coming soon)
Environment Variables
| Variable | Description | Example |
|---|---|---|
JWT_SECRET | RSA private key or secret | Base64 encoded key |
GOOGLE_CLIENT_ID | Google OAuth client ID | xxx.apps.googleusercontent.com |
GOOGLE_CLIENT_SECRET | Google OAuth secret | Secret string |
GITHUB_CLIENT_ID | GitHub OAuth client ID | GitHub app ID |
GITHUB_CLIENT_SECRET | GitHub OAuth secret | Secret string |
TOKEN_EXPIRY | Token lifetime | 7d, 24h, 3600 |
SDK References
Choose the authentication SDK guide for your platform:TypeScript
Web and Node.js applications with full OAuth and session management
Swift
iOS, macOS, tvOS, and watchOS with Sign in with Apple support
Kotlin
Android applications with Google Sign-In integration
Flutter
Cross-platform mobile apps for iOS and Android
UI Components (TypeScript)
For web applications, we also provide pre-built authentication UI components:React
React + Vite apps
Next.js
Next.js with SSR
Custom UI
Build your own