Authsomeβ’ is an authentication and authorization backend maintained by XRAPHβ’.
Authors: Rex Raphael Last Updated: 2025-11-01
A comprehensive, pluggable authentication framework for Go, inspired by better-auth. Enterprise-grade authentication with multi-tenancy support, designed to integrate seamlessly with the Forge framework.
- Email/Password Authentication - Secure user registration and login
- Session Management - Cookie-based sessions with Redis caching support
- Multi-Factor Authentication - TOTP, SMS, and email-based 2FA
- Social Authentication - OAuth integration with major providers
- Passwordless Authentication - Magic links and WebAuthn/Passkeys
- Multi-Tenancy - Organization-scoped authentication and configuration
- Role-Based Access Control (RBAC) - Fine-grained permissions and policies
- Audit Logging - Comprehensive security event tracking
- Rate Limiting - Configurable request throttling and abuse prevention
- Device Management - Track and manage user devices and sessions
- Security Monitoring - IP filtering, geolocation, and anomaly detection
- Plugin Architecture - Extensible authentication methods
- Clean Architecture - Service-oriented design with repository pattern
- Type Safety - Full Go type safety with comprehensive error handling
- Database Agnostic - PostgreSQL, MySQL, and SQLite support
- Configuration Management - Flexible YAML/JSON configuration with environment overrides
- Comprehensive Testing - Unit and integration test coverage
- Standalone Mode - Single-tenant applications
- SaaS Mode - Multi-tenant platforms with organization isolation
- Go 1.25 or later
- Supported database (PostgreSQL, MySQL, or SQLite)
- Redis (optional, for distributed session storage)
go get github.com/xraph/authsome# Core dependencies
go get github.com/xraph/forge
go get github.com/uptrace/bun
# Database drivers (choose one)
go get github.com/lib/pq # PostgreSQL
go get github.com/go-sql-driver/mysql # MySQL
go get github.com/mattn/go-sqlite3 # SQLite
# Optional: Redis for session storage
go get github.com/redis/go-redis/v9package main
import (
"context"
"log"
"os"
"github.com/xraph/authsome"
"github.com/xraph/forge"
"github.com/uptrace/bun"
"github.com/uptrace/bun/dialect/pgdialect"
"github.com/uptrace/bun/driver/pgdriver"
)
func main() {
// Create Forge app
app := forge.New()
// Setup database
db := bun.NewDB(pgdriver.NewConnector(
pgdriver.WithDSN(os.Getenv("DATABASE_URL")),
), pgdialect.New())
// Initialize AuthSome
auth := authsome.New(
authsome.WithDatabase(db),
authsome.WithForgeConfig(app.Config()),
authsome.WithMode(authsome.ModeStandalone),
)
// Initialize services
if err := auth.Initialize(context.Background()); err != nil {
log.Fatal("Failed to initialize AuthSome:", err)
}
// Mount AuthSome routes
if err := auth.Mount(app, "/auth"); err != nil {
log.Fatal("Failed to mount AuthSome:", err)
}
// Start server
log.Println("Server starting on :8080")
log.Fatal(app.Listen(":8080"))
}Create a .env file:
# Database
DATABASE_URL=postgres://user:password@localhost/myapp?sslmode=disable
# Session
SESSION_SECRET=your-super-secret-session-key
# Email (optional)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
[email protected]
SMTP_PASSWORD=your-app-password
# Redis (optional)
REDIS_URL=redis://localhost:6379curl -X POST http://localhost:8080/auth/register \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "securepassword123"
}'curl -X POST http://localhost:8080/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "securepassword123"
}'// Middleware for protected routes
func requireAuth(auth *authsome.Auth) forge.MiddlewareFunc {
return func(c *forge.Context) error {
session := auth.GetSession(c)
if session == nil {
return c.JSON(401, map[string]string{
"error": "Authentication required",
})
}
return c.Next()
}
}
// Protected route example
app.GET("/api/profile", requireAuth(auth), func(c *forge.Context) error {
user := auth.GetUser(c)
return c.JSON(200, user)
})import (
"github.com/xraph/authsome/plugins/twofa"
"github.com/xraph/authsome/plugins/username"
"github.com/xraph/authsome/plugins/magiclink"
)
// Initialize with plugins
auth := authsome.New(
authsome.WithDatabase(db),
authsome.WithForgeConfig(app.Config()),
authsome.WithPlugins(
twofa.NewPlugin(),
username.NewPlugin(),
magiclink.NewPlugin(),
),
)# config.yaml
auth:
mode: "standalone" # or "saas"
basePath: "/auth"
secret: "your-session-secret"
rbacEnforce: false
# Session configuration
session:
maxAge: 86400 # 24 hours
secure: true
httpOnly: true
sameSite: "strict"
# Rate limiting
rateLimit:
enabled: true
requests: 100
window: "1m"
storage: "memory" # or "redis"
# Email configuration
email:
provider: "smtp"
smtp:
host: "smtp.gmail.com"
port: 587
username: "[email protected]"
password: "your-app-password"
# Security settings
security:
enabled: true
ipWhitelist: []
ipBlacklist: []
allowedCountries: ["US", "CA", "GB"]
blockedCountries: ["CN", "RU"]
# Plugin configurations
plugins:
twofa:
enabled: true
issuer: "MyApp"
digits: 6
period: 30
username:
enabled: true
minLength: 3
maxLength: 30
allowSpecialChars: false
magiclink:
enabled: true
tokenExpiry: "15m"
maxAttempts: 3# Core settings
AUTHSOME_MODE=standalone
AUTHSOME_SECRET=your-session-secret
AUTHSOME_BASE_PATH=/auth
# Database
DATABASE_URL=postgres://user:pass@localhost/db
# Session
SESSION_MAX_AGE=86400
SESSION_SECURE=true
# Rate limiting
RATE_LIMIT_ENABLED=true
RATE_LIMIT_REQUESTS=100
RATE_LIMIT_WINDOW=1m
# Email
EMAIL_PROVIDER=smtp
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
[email protected]
SMTP_PASSWORD=your-app-password
# Redis (optional)
REDIS_URL=redis://localhost:6379
# Security
SECURITY_ENABLED=true
ALLOWED_COUNTRIES=US,CA,GB
BLOCKED_COUNTRIES=CN,RU| Method | Endpoint | Description |
|---|---|---|
POST |
/auth/register |
Register a new user |
POST |
/auth/login |
Authenticate user |
POST |
/auth/logout |
End user session |
POST |
/auth/refresh |
Refresh session |
GET |
/auth/me |
Get current user |
PUT |
/auth/me |
Update user profile |
POST |
/auth/change-password |
Change user password |
POST |
/auth/forgot-password |
Request password reset |
POST |
/auth/reset-password |
Reset password with token |
| Method | Endpoint | Description |
|---|---|---|
POST |
/auth/2fa/setup |
Setup 2FA for user |
POST |
/auth/2fa/verify |
Verify 2FA token |
POST |
/auth/2fa/disable |
Disable 2FA |
GET |
/auth/2fa/backup-codes |
Get backup codes |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/orgs |
List user organizations |
POST |
/api/orgs |
Create organization |
GET |
/api/orgs/{id} |
Get organization details |
PUT |
/api/orgs/{id} |
Update organization |
DELETE |
/api/orgs/{id} |
Delete organization |
GET |
/api/orgs/{id}/members |
List organization members |
POST |
/api/orgs/{id}/invite |
Invite user to organization |
DELETE |
/api/orgs/{id}/members/{userId} |
Remove member |
| Method | Endpoint | Description |
|---|---|---|
GET |
/auth/sessions |
List user sessions |
DELETE |
/auth/sessions/{id} |
Revoke specific session |
DELETE |
/auth/sessions/all |
Revoke all sessions |
| Method | Endpoint | Description |
|---|---|---|
GET |
/auth/audit |
Get audit logs |
GET |
/auth/devices |
List user devices |
DELETE |
/auth/devices/{id} |
Remove device |
| Method | Endpoint | Description |
|---|---|---|
GET |
/auth/webhooks |
List webhooks |
POST |
/auth/webhooks |
Create webhook |
PUT |
/auth/webhooks/{id} |
Update webhook |
DELETE |
/auth/webhooks/{id} |
Delete webhook |
| Method | Endpoint | Description |
|---|---|---|
GET |
/auth/api-keys |
List API keys |
POST |
/auth/api-keys |
Create API key |
DELETE |
/auth/api-keys/{id} |
Revoke API key |
We welcome contributions to AuthSome! Please follow these guidelines:
-
Fork and clone the repository
git clone https://github.com/your-username/authsome.git cd authsome -
Install dependencies
go mod download
-
Set up development database
# Using Docker docker run --name authsome-postgres -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres:15 # Create test database createdb -h localhost -U postgres authsome_test
-
Run tests
go test ./... -
Run integration tests
make test-integration
- Follow standard Go conventions and use
gofmt - Write comprehensive tests for new features
- Add function-level comments for exported functions
- Use meaningful variable and function names
- Follow the existing architecture patterns
-
Create a feature branch
git checkout -b feature/your-feature-name
-
Make your changes
- Write tests for new functionality
- Update documentation as needed
- Ensure all tests pass
-
Commit your changes
git commit -m "feat: add your feature description" -
Push and create a pull request
git push origin feature/your-feature-name
- Provide a clear description of the changes
- Include tests for new functionality
- Update documentation if needed
- Ensure CI passes
- Link to any relevant issues
When reporting issues, please include:
- Go version
- AuthSome version
- Database type and version
- Minimal reproduction case
- Error messages and stack traces
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2024 AuthSome Contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- Official Documentation: https://authsome.dev
- API Reference: https://authsome.dev/api
- Examples: https://github.com/xraph/authsome/tree/main/examples
- GitHub Discussions: https://github.com/xraph/authsome/discussions
- Discord Server: https://discord.gg/authsome
- Stack Overflow: Tag your questions with
authsome-go
For enterprise support, consulting, and custom development:
- Email: [email protected]
- Enterprise: [email protected]
- Website: https://authsome.dev/enterprise
For security-related issues, please email: [email protected]
Do not report security issues through public GitHub issues.
Website β’ Documentation β’ Examples β’ Contributing
Made with β€οΈ by the AuthSome team