A complete, enterprise-grade auth backend β JWT, OAuth 2.0 Provider, MFA, RBAC, Social Login β
in a single deployable Go binary.
Explore the API β Β Β Β·Β Β Report Bug Β Β Β·Β Β Request Feature Β Β Β·Β Β Contributing
Building authentication from scratch is tedious, error-prone, and takes weeks away from your actual product. Auth Server gives you a battle-tested, self-hosted auth backend that deploys in under 5 minutes.
Ship your product, not your auth layer.
|
|
| π Core Authentication | π‘ Security & Compliance |
|---|---|
|
β’ JWT access & refresh token rotation |
β’ BCrypt password hashing |
| π OAuth 2.0 Provider | π§© Developer Experience |
|
β’ Authorization Code flow (PKCE-ready) |
β’ TypeScript SDK on npm |
| Status | Feature | Description |
|---|---|---|
| π | Webhooks | Notify external systems on auth events (login, register, lock) |
| π | SAML / SSO | Enterprise single sign-on for corporate identity providers |
| π | Passkeys / WebAuthn | Passwordless authentication with biometrics |
| π | Flutter SDK | Mobile-first auth client for iOS & Android |
| π | Go SDK | Server-to-server auth client for microservice architectures |
| π | Magic Links | Passwordless email-based login flow |
Have an idea? Open a discussion β
Auth Server follows Clean Architecture with strict separation of concerns:
auth-server/
βββ cmd/server/main.go # Entry point β Gin setup, GORM migration, graceful shutdown
βββ internal/
β βββ config/ # Configuration loading, DB & Redis initialization
β βββ routes/ # Route definitions & middleware registration
β βββ handler/ # HTTP handlers β request parsing & response formatting
β βββ service/ # Business logic β auth flows, OAuth, MFA, email
β βββ repository/ # Data access layer β isolated GORM queries
β βββ models/ # GORM models β User, RefreshToken, OAuthClient, etc.
β βββ middleware/ # Auth, CORS, CSP, rate limiting, recovery
β βββ dto/ # Request/response data transfer objects
β βββ utils/ # Helpers β validation, error types, JWT claims
βββ clients/ts/ # Official TypeScript SDK (published to npm)
βββ templates/ # Email templates (HTML)
βββ docs/ # Swagger UI & generated API spec
βββ docker-compose.yml # PostgreSQL + Redis orchestration
| Layer | Technology | Purpose |
|---|---|---|
| Language | Go 1.25+ | High-performance compiled backend |
| Framework | Gin Gonic | Fast HTTP router with middleware pipeline |
| Database | PostgreSQL 15+ | Relational data store via GORM ORM |
| Cache | Redis 7+ | Rate limiting, token blacklist, sessions |
| Auth | JWT + OAuth 2.0 + TOTP | Industry-standard protocols |
| Hashing | BCrypt | Secure password storage |
| SMTP (Gmail, SendGrid, etc.) | Transactional email delivery | |
| Docs | Swagger / OpenAPI 3.0 | Interactive API documentation |
| SDK | TypeScript | React, Next.js, & Node.js bindings |
| Deploy | Docker & Docker Compose | Containerized deployment |
- Go 1.25+ Β Β·Β Docker & Docker Compose Β Β·Β PostgreSQL 15+ Β Β·Β Redis 7+
git clone https://github.com/roshankumar0036singh/auth-server.git
cd auth-server
cp .env.example .env # β configure your secrets
docker compose up --build -dServer runs at http://localhost:8080 Β Β·Β Swagger UI at /swagger/
git clone https://github.com/roshankumar0036singh/auth-server.git
cd auth-server
# Install dependencies
go mod download
# Configure environment
cp .env.example .env
# Start PostgreSQL & Redis
docker compose up -d db redis
# Run the server
go run cmd/server/main.gomake run # Start the server
make test # Run all tests
make swagger # Regenerate API docs
make build-prod # Static production binary| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/register |
Create a new account |
POST |
/api/auth/login |
Authenticate with credentials |
POST |
/api/auth/login/mfa |
Complete MFA challenge |
POST |
/api/auth/refresh |
Refresh access token |
POST |
/api/auth/logout |
Revoke current session |
POST |
/api/auth/logout-all |
Revoke all sessions |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/auth/me |
Get current user profile |
PUT |
/api/auth/profile |
Update profile |
POST |
/api/auth/password |
Change password |
DELETE |
/api/auth/me |
Delete account |
GET |
/api/auth/sessions |
List active sessions |
DELETE |
/api/auth/sessions/:id |
Revoke specific session |
GET |
/api/auth/audit-logs |
View audit trail |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/auth/verify-email |
Verify email address |
POST |
/api/auth/resend-verification |
Resend verification email |
POST |
/api/auth/forgot-password |
Request password reset |
POST |
/api/auth/reset-password |
Reset password with token |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/auth/mfa/enable |
Generate TOTP secret |
POST |
/api/auth/mfa/verify |
Verify and activate MFA |
POST |
/api/auth/mfa/disable |
Disable MFA |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/auth/google/login |
Initiate Google OAuth |
GET |
/api/auth/google/callback |
Google OAuth callback |
GET |
/api/auth/github/login |
Initiate GitHub OAuth |
GET |
/api/auth/github/callback |
GitHub OAuth callback |
| Method | Endpoint | Description |
|---|---|---|
GET |
/oauth/authorize |
Authorization endpoint |
POST |
/oauth/token |
Token exchange |
GET |
/oauth/userinfo |
Get authorized user info |
POST |
/api/auth/oauth/clients |
Register OAuth client |
GET |
/api/auth/oauth/clients |
List your OAuth clients |
DELETE |
/api/auth/oauth/clients/:id |
Delete OAuth client |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/admin/users |
List all users (paginated) |
POST |
/api/admin/users/:id/lock |
Lock user account |
POST |
/api/admin/users/:id/unlock |
Unlock user account |
DELETE |
/api/admin/users/:id |
Delete user account |
The official SDK is published on npm as @authserver/client.
npm install @authserver/clientimport { AuthClient } from '@authserver/client';
const auth = new AuthClient({
serverUrl: 'https://your-auth-server.com',
clientId: 'your-client-id',
storage: 'localStorage',
keepAlive: true, // prevents server sleep on free-tier hosting
});
// Register & login
await auth.register('[email protected]', 'securePassword123', 'John');
const session = await auth.login('[email protected]', 'securePassword123');
// Automatic token refresh β just call methods
const user = await auth.getUser();
// Listen for auth events
auth.on('logout', () => console.log('User signed out'));
// Cleanup when done
auth.destroy();import { AuthProvider, useAuth } from '@authserver/client/react';
function App() {
return (
<AuthProvider serverUrl="https://your-auth-server.com" clientId="your-client-id">
<Dashboard />
</AuthProvider>
);
}
function Dashboard() {
const { user, login, logout, isAuthenticated } = useAuth();
if (!isAuthenticated) return <button onClick={() => login('[email protected]', 'pw')}>Login</button>;
return <p>Welcome, {user?.name}! <button onClick={logout}>Logout</button></p>;
}import { createNextAuthClient } from '@authserver/client/nextjs';
export const { withAuth, getSession, handlers } = createNextAuthClient({
serverUrl: 'https://your-auth-server.com',
clientId: 'your-client-id',
});import { AdminClient } from '@authserver/client/admin';
const admin = new AdminClient({
serverUrl: 'https://your-auth-server.com',
adminToken: 'your-admin-jwt',
});
const users = await admin.listUsers();
await admin.lockUser('user-uuid');Copy .env.example to .env and configure:
| Variable | Required | Description |
|---|---|---|
APP_ENV |
Yes | development or production |
DATABASE_URL |
Yes | PostgreSQL connection string |
REDIS_URL |
Yes | Redis connection string |
JWT_SECRET |
Yes | Access token signing key |
JWT_REFRESH_SECRET |
Yes | Refresh token signing key |
SMTP_HOST |
Yes | Email SMTP server |
SMTP_USER / SMTP_PASSWORD |
Yes | SMTP credentials |
GOOGLE_CLIENT_ID / SECRET |
No | Google OAuth (optional) |
GITHUB_CLIENT_ID / SECRET |
No | GitHub OAuth (optional) |
PING_URL |
No | Self-ping URL to prevent free-tier sleep |
ENCRYPTION_KEY |
Yes | 32-byte key for sensitive data encryption |
BCRYPT_ROUNDS |
No | Password hashing cost (default: 12) |
# Run all tests
go test ./...
# Run tests with verbose output
go test ./internal/service -v
# Run a specific test
go test ./internal/service -run TestTokenService_GenerateAccessToken -v
# Generate HTML coverage report
go test ./... -coverprofile=coverage.out && go tool cover -html=coverage.outdocker compose up --build -dThis starts:
- Auth Server on port
8080 - PostgreSQL on port
5432 - Redis on port
6379
# Static binary (no CGO dependencies)
make build-prod
# Or manually:
CGO_ENABLED=0 GOOS=linux go build -o auth-server cmd/server/main.go| Platform | Guide |
|---|---|
| Render | Connect repo β set env vars β auto-deploy |
| Railway | One-click Go template β configure .env |
| Fly.io | fly launch β fly deploy |
| AWS / GCP / Azure | Docker image or binary deployment |
Tip: Set
PING_URLto your public URL's/healthendpoint to prevent free-tier platforms from putting your server to sleep. Auth Server includes a built-in self-pinger that hits this URL every 14 minutes.
We welcome contributions of all sizes β from typo fixes to new features.
# Fork β Clone β Branch
git checkout -b feature/your-feature
# Make changes β Test
go test ./...
# Commit (we use Conventional Commits)
git commit -m "feat: add amazing feature"
# Push β Open PR
git push origin feature/your-featureRead the full Contributing Guide β Β Β·Β Code of Conduct β
- Bug reports β Open an issue
- Feature requests β Start a discussion
- Documentation β Improve guides, add examples
- Tests β Increase coverage, add edge cases
- Integrations β Build SDKs for other languages
Distributed under the MIT License. See LICENSE for details.
Roshan Kumar Singh