A production-grade, full-stack authentication and identity security platform built with React 19, TypeScript, Tailwind CSS, Spring Boot 4, Spring Security, JWT, OAuth 2.0, and MySQL.
AuthSphere implements a complete enterprise authentication lifecycle featuring feature-wise (package-by-feature) architecture on both the backend and frontend, stateless JWT access tokens, HttpOnly rotating refresh tokens, TOTP 2FA with backup recovery codes, real-time device session management, X-API-Key developer authentication, dynamic security scoring, audit logging, and an admin console.
- User Registration & Login: BCrypt password hashing,
@ValidDTO validation, and automaticROLE_USERassignment viaDataInitializer. - Stateless JWT + Rotating Refresh Tokens:
HS512signed access tokens (JwtService) paired with DB-backed rotating refresh tokens stored inHttpOnlycookies (CookieService). - XSS-Hardened In-Memory Access Token: Frontend Zustand store (
authStore.ts) keepsaccessTokenstrictly in memory (excluded fromlocalStorageviapartialize) and silently hydrates it from theHttpOnlycookie on page reload. - Concurrent 401 Refresh Queue: Axios interceptors (
ApiClient.ts) automatically queue concurrent401requests during an active refresh and retry them seamlessly. - Forgot Password & Email Verification: Tokenized password reset (
15mTTL) and email verification (24hTTL) viaEmailService(supports SMTP or dev console fallback).
- Google & GitHub Login: Automatic user provisioning, GitHub private-email fallback, session tracking, audit logging, and dedicated
/auth/successand/auth/failureUI flows.
- Google Authenticator / Authy Support: RFC 6238
HmacSHA1TOTP secret generation, QR code setup modal, and 6-digit verification (TotpService). - Single-Use Backup Recovery Codes: Generates 8 BCrypt-hashed recovery codes (
XXXX-XXXX) upon 2FA activation.
- IP Rate Limiting:
RateLimitFilterrestricts/login,/register, and/forgot-passwordto 15 requests/minute per IP (429 Too Many Requests). - Brute-Force Lockout: Locks accounts for 15 minutes after 5 consecutive failed login attempts.
- Dynamic Security Score & Audit Trail: Real-time score calculation (
SecurityServiceImpl) andaudit_logstracking (LOGIN,OAUTH_LOGIN,LOGOUT,TOKEN_REFRESH,PASSWORD_CHANGE,API_KEY_CREATED,API_KEY_REVOKED,SESSION_REVOKED,ACCOUNT_LOCKED, etc.).
- Tracks active sessions in
user_sessionswith IP address, browser, OS, device type, approximate location, and refresh token JTI. - View all active devices and remotely revoke individual sessions or all other sessions (simultaneously revoking their refresh tokens).
- Generate
as_live_andas_test_keys usingSecureRandom. - Only SHA-256 hashes are stored in
api_keys; the plain-text secret is displayed once on creation. - Live
ApiKeyAuthenticationFilterauthenticates external REST requests via theX-API-Keyheader and updateslastUsedAt.
- Profile & Settings: Update display name, change password (with current-password verification), persist notification/tracking/rotation preferences in
user_settings, and delete own account. - Admin Console (
/dashboard/admin): Role-gated (ROLE_ADMIN) dashboard displaying system metrics, user directory, lock/unlock controls, enable/disable toggles, role management, and system-wide audit logs. - Scheduled Cleanup:
@Scheduledhourly job (TokenCleanupScheduler) purges expired/revoked refresh tokens, verification tokens, and stale sessions.
├── AuthsphereBackendApplication.java
├── admin/ (controller, dto, service)
├── apikey/ (controller, dto, entity, repository, security, service)
├── auth/ (controller, dto, entity, repository, security, service)
├── common/ (config, dtos, exceptions, helpers, scheduler, service)
├── security/ (controller, dto, entity, repository, service)
├── session/ (controller, dto, entity, repository, service)
└── user/ (controller, dto, entity, repository, service)
├── App.tsx
├── main.tsx
├── components/ui/ (shadcn/ui primitives)
├── hooks/
├── lib/
└── features/
├── admin/ (models, pages, services)
├── apikeys/ (models, pages, services)
├── auth/ (components, models, pages, services, store)
├── common/ (components, config, layouts)
├── public/ (pages)
├── security/ (models, pages, services)
├── sessions/ (models, pages, services)
└── user/ (models, pages, services)
| Module | Method & Endpoint | Description |
|---|---|---|
| Auth | POST /auth/register, POST /auth/login, POST /auth/refresh, POST /auth/logout |
Core authentication & token lifecycle |
| Recovery | POST /auth/forgot-password, POST /auth/reset-password, POST /auth/verify-email |
Password reset & email verification |
| User | GET /users/me, PUT /users/profile, PUT /users/change-password, GET/PUT /users/settings, DELETE /users/me |
Profile, password, settings & deletion |
| Sessions | GET /sessions, DELETE /sessions/{id}, DELETE /sessions/other |
Active device listing & revocation |
| API Keys | POST /api-keys, GET /api-keys, DELETE /api-keys/{id} |
API key creation, listing & revocation |
| Security | GET /security/overview, POST /security/two-factor/setup, POST /security/two-factor/verify, PUT /security/two-factor |
Security score, audit logs & TOTP 2FA |
| Admin | GET /admin/stats, GET /admin/users, PUT /admin/users/{id}/unlock, PUT /admin/users/{id}/status, PUT /admin/users/{id}/role |
Admin console (ROLE_ADMIN only) |
Interactive API docs available at
http://localhost:8083/swagger-ui.html.
Starts MySQL 8.4 (3306), Spring Boot Backend (8083), and React + Nginx Frontend (5173):
docker compose up --buildEnsure MySQL is running on localhost:3306 (configured in src/main/resources/application-dev.yaml), then run:
cd authsphere-backend
.\mvnw.cmd spring-boot:runCreate authsphere-frontend/.env (see .env.example):
VITE_API_BASE_URL=http://localhost:8083/api/m1
VITE_BASE_URL=http://localhost:8083Then install and start:
cd authsphere-frontend
npm install
npm run dev| Variable | Purpose |
|---|---|
DB_URL, DB_USERNAME, DB_PASSWORD |
MySQL connection settings |
JWT_SECRET |
64+ character secret for HS512 JWT signing |
GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET |
Google OAuth 2.0 credentials |
GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET |
GitHub OAuth 2.0 credentials |
SPRING_MAIL_HOST, SPRING_MAIL_PORT, SPRING_MAIL_USERNAME, SPRING_MAIL_PASSWORD |
SMTP server for real email delivery |
COOKIE_SECURE |
Set true in HTTPS production environments |
# Backend integration tests (runs against H2 in-memory DB via test profile)
cd authsphere-backend
.\mvnw.cmd test
# Frontend TypeScript check + Vite production build
cd authsphere-frontend
npm run build