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 | Social authentication |
Token Expiry | Fixed | 7 days for user tokens, never for anon tokens |
Authentication Flow
Password-Based Authentication
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/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/google | Initiate Google OAuth flow |
GET | /api/auth/oauth/github | Initiate GitHub OAuth flow |
GET | /api/auth/oauth/:provider/callback | 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
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
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 _accounts 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 |