Skip to content

Deepractice/EdgeAuth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

90 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

EdgeAuth ยท Edge-Native Authentication Service

๐ŸŒ Authentication at the Speed of Light - Globally distributed, zero-latency auth built on Cloudflare's edge

Core Capabilities: JWT Authentication | OAuth 2.0 Provider | SSO Sessions | Admin Management

Serverless authentication service that runs on Cloudflare Workers - simple, secure, and globally fast

Stars Views License

TypeScript Cloudflare Workers D1 Database Hono

Architecture | Schema | API


๐Ÿš€ Why EdgeAuth?

โšก Edge-First Architecture

Built on Cloudflare Workers, your authentication runs in 300+ cities worldwide. Users get sub-10ms response times, no matter where they are.

๐ŸŽฏ Simple by Design

No complex setup. No infrastructure management. Just deploy and use.

// That's it. Authentication in 3 lines.
const token = await auth.login(email, password);
const user = await auth.verify(token);
const session = await sso.createSession(user);

๐Ÿ—๏ธ Clean Architecture

Built with Domain-Driven Design and clean architecture principles:

  • Domain Layer: Pure business logic
  • Core Layer: Technical implementation (crypto, JWT, persistence)
  • Services Layer: Edge-native workers

๐Ÿ” Security First

  • PBKDF2 password hashing with Web Crypto API
  • HS256 JWT tokens
  • Secure session management
  • Built-in rate limiting (coming soon)

โšก Quick Start

๐Ÿ“ฆ Installation

# Clone the repository
git clone https://github.com/Deepractice/EdgeAuth.git
cd EdgeAuth

# Install dependencies
pnpm install

๐Ÿš€ Production Deployment

Automated deployment via GitHub Actions:

  1. Create a release/v0.x.x branch
  2. Merge to main
  3. Deployment happens automatically!

Required GitHub Secrets:

CLOUDFLARE_API_TOKEN  # Cloudflare API token with D1 and Workers permissions
GH_PAT                # GitHub Personal Access Token with repo and workflow permissions
JWT_SECRET            # Secret key for JWT signing (generate with: openssl rand -base64 32)
PLUNK_API_KEY         # Plunk email service API key

All secrets are automatically configured to Workers during deployment - no manual Cloudflare secret management needed!

๐Ÿ’ป Local Development

One-command setup:

# Set up local environment (creates local DBs, runs migrations)
pnpm setup:local

# Start a worker
cd services/account-api && wrangler dev

๐Ÿ“– Full Deployment Guide โ†’


๐ŸŽจ Features

โœ… Current (v0.1)

  • โœจ Email/Username + Password Authentication
  • ๐Ÿ”‘ JWT Token Generation & Validation
  • ๐Ÿ” Secure Password Hashing (PBKDF2)
  • ๐ŸŒ Edge-Native Performance
  • ๐Ÿ“ฆ Cloudflare D1 Persistence
  • ๐ŸŽฏ Clean REST API
  • ๐Ÿ“š Full TypeScript Support

๐Ÿšง In Progress

  • ๐Ÿ”„ SSO Session Management
  • ๐Ÿ‘จโ€๐Ÿ’ผ Admin Management API
  • ๐Ÿ”Œ OAuth 2.0 Provider (complete)

๐Ÿ“‹ Planned

  • ๐Ÿ“ง Email Verification
  • ๐Ÿ”„ Password Reset Flow
  • ๐ŸŽจ Admin Dashboard (UI)
  • ๐Ÿ“ฆ SDK Libraries (JS/TS, Python, Go)
  • โšก Refresh Token Support
  • ๐Ÿšฆ Rate Limiting
  • ๐Ÿ”— OAuth Providers (GitHub, Google, etc.)

๐Ÿ“ Architecture

EdgeAuth uses a single database architecture with Cloudflare's native migration system:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚              edgeauth-db (Single Database)          โ”‚
โ”‚  โ€ข users table                                      โ”‚
โ”‚  โ€ข sso_sessions table                               โ”‚
โ”‚  โ€ข oauth_clients, tokens tables                     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ–ผ             โ–ผ                 โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Admin Worker โ”‚ โ”‚  SSO Worker  โ”‚ โ”‚ OAuth Worker โ”‚
โ”‚ โ€ข User CRUD  โ”‚ โ”‚  โ€ข Auth flow โ”‚ โ”‚  โ€ข OAuth 2.0 โ”‚
โ”‚ โ€ข Binds: DB  โ”‚ โ”‚  โ€ข Binds: DB โ”‚ โ”‚  โ€ข Binds: DB โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ—„๏ธ Single Database

  • edgeauth-db - All tables in one database
    • users - User accounts
    • sso_sessions - SSO sessions
    • oauth_clients, authorization_codes, access_tokens, refresh_tokens - OAuth

โœจ Key Benefits

  • โœ… Cloudflare native migrations (automatic tracking)
  • โœ… Idempotent deployments
  • โœ… Simplified management
  • โœ… No cross-database complexity

๐Ÿ“– Read Full Architecture Docs โ†’


๐Ÿ› ๏ธ API Examples

Register New User

POST /auth/register
Content-Type: application/json

{
  "email": "user@example.com",
  "username": "username",
  "password": "securepassword"
}

Login

POST /auth/login
Content-Type: application/json

{
  "account": "user@example.com",  // email or username
  "password": "securepassword"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "user": {
    "id": "user_123",
    "email": "user@example.com",
    "username": "username"
  }
}

Get Current User

GET /auth/me
Authorization: Bearer <token>

๐Ÿงช Development

Run Tests

# Run all tests
pnpm test

# Watch mode
pnpm test:dev

# Coverage
pnpm test:ci

Type Checking

pnpm typecheck

Format Code

# Format all files
pnpm format

# Check formatting
pnpm format:check

๐Ÿ“š Technology Stack

Category Technology
Runtime Cloudflare Workers
Database Cloudflare D1 (SQLite)
Framework Hono
Language TypeScript 5.9+
Build tsup, Turbo
Test Vitest + BDD (Cucumber)
Security Web Crypto API (PBKDF2), JWT (HS256)
Monorepo pnpm workspaces

๐ŸŽ“ Project Structure

EdgeAuth/
โ”œโ”€โ”€ migrations/            # Database migrations (Cloudflare native)
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ core/              # Technical core (crypto, JWT, persistence)
โ”‚   โ””โ”€โ”€ domain/            # Business logic (User, OAuth, SSO)
โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ admin-api/         # Admin API
โ”‚   โ”œโ”€โ”€ account-api/       # User registration & login
โ”‚   โ”œโ”€โ”€ oauth-api/         # OAuth 2.0 Provider
โ”‚   โ””โ”€โ”€ sso-api/           # SSO authentication
โ”œโ”€โ”€ .github/workflows/     # CI/CD pipelines
โ”œโ”€โ”€ docs/                  # Documentation
โ””โ”€โ”€ scripts/               # Development scripts

๐Ÿค Contributing

Contributions are welcome! Please read our Contributing Guide for details.

Development Process

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿข About

Proudly brought to you by Deepractice

Making AI your professional partner

๐ŸŒ Official Site | ๐Ÿ”ง GitHub | ๐Ÿ“š Documentation | ๐Ÿ’ฌ Forum | ๐ŸŽฎ Discord

Connect with Founder

Sean's WeChat

Scan to connect with Sean (Founder & CEO) on WeChat


๐Ÿ“ž Support

About

Deepractice Account System

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors