A lightweight Single Sign-On (SSO) system built with Go.
中文文档 (Chinese) | Contributing | Changelog
- Web Framework: Gin
- Database: SQLite (Default) / MySQL 8 / PostgreSQL + GORM
- Cache: Redis
- Authentication: JWT (Access Token + Refresh Token)
- Configuration: Viper
lite-auth/
├── cmd/
│ └── server/
│ └── main.go # Entry point
├── config/
│ └── config.yaml # Configuration file
├── internal/
│ ├── config/ # Configuration loading
│ ├── database/ # Database initialization (SQLite, MySQL, Postgres) & Redis
│ ├── handler/ # HTTP handlers (Controllers)
│ ├── middleware/ # Middleware (JWT, CORS, etc.)
│ ├── model/ # Data models
│ ├── repository/ # Data access layer (DAO)
│ ├── router/ # Route definitions
│ └── service/ # Business logic layer
├── pkg/
│ └── jwt/ # JWT utilities
├── test/
│ └── api/
│ └── auth.http # API test scripts
├── go.mod
└── README.md
Ensure you have the following installed:
- Go 1.21+
- Redis 6.0+ (Required for session management)
- Optional: MySQL or PostgreSQL (if you don't want to use the default SQLite)
By default, the project uses SQLite, so no database setup is required to get started.
-
Clone the repository:
git clone https://github.com/joshleeeeee/go-lite-auth.git cd go-lite-auth -
Sync dependencies:
go mod tidy
-
Run the application:
go run cmd/server/main.go
The application will automatically create data/lite_auth.db and start immediately.
If you want to use a different database, edit config/config.yaml:
- Change
database.drivertomysqlorpostgres. - Update the corresponding section (
mysqlorpostgres) with your credentials. - Create the database manually if using MySQL/Postgres:
CREATE DATABASE lite_auth CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
go mod tidygo run cmd/server/main.goThe server will start at http://localhost:8080.
| Method | Path | Description | Auth Required |
|---|---|---|---|
| POST | /api/auth/register |
User Registration | ❌ |
| POST | /api/auth/login |
User Login | ❌ |
| POST | /api/auth/logout |
User Logout | ✅ |
| POST | /api/auth/refresh |
Refresh Token | ❌ |
| GET | /api/auth/validate |
Validate Token | ❌ |
| Method | Path | Description | Auth Required |
|---|---|---|---|
| GET | /api/user/info |
Get current user info | ✅ |
| Method | Path | Description | Auth Required |
|---|---|---|---|
| GET | /sso/login?service=xxx |
SSO login entry | ❌ |
| POST | /sso/login |
Submit login, returns Service Ticket | ❌ |
| GET | /sso/validate?ticket=xxx&service=xxx |
Validate Service Ticket | ❌ |
| GET | /sso/logout |
SSO logout | ❌ |
For more comprehensive examples including SSO flows, see the HTTP test files in
test/api/.
curl -X POST http://localhost:8080/api/auth/register \
-H "Content-Type: application/json" \
-d '{"username":"test","email":"test@example.com","password":"123456"}'curl -X POST http://localhost:8080/api/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"test","password":"123456"}'curl http://localhost:8080/api/user/info \
-H "Authorization: Bearer <access_token>"| Prefix | Purpose | TTL |
|---|---|---|
session: |
User session data | 24 hours |
blacklist: |
Revoked JWT tokens | Remaining JWT TTL |
ticket: |
SSO Tickets | 60 seconds |
login_fail: |
Login failure counter | 5 minutes |
- SSO Ticket mechanism (CAS-style)
- OAuth 2.0 Authorization Code Flow
- Frontend login page
- Client application management
- Admin dashboard
Contributions are welcome! Please see CONTRIBUTING.md for guidelines.
MIT