ShieldGate is a production-grade OAuth 2.0 and OpenID Connect (OIDC) Authorization Server written in Go 1.21+. It provides centralized authentication and authorization for multiple client types (web apps, SPAs, mobile, machine-to-machine).
Key capabilities: Authorization Code + PKCE flow, Client Credentials, multi-tenancy, RBAC, audit logging, JWT token management, Redis caching, and OIDC discovery.
| Layer | Technology |
|---|---|
| Language | Go 1.21+ (toolchain 1.24.2) |
| Web framework | Gin v1.9.1 |
| Database | PostgreSQL 13+ via GORM |
| Cache | Redis 6+ (optional) |
| Auth tokens | golang-jwt/jwt v5 |
| Config | Viper (YAML + env vars) |
| Logging | Logrus (structured JSON) |
| Testing | Go standard + testify |
| Containers | Docker + Docker Compose |
cp .env.example .env # fill in secrets
make start # starts Postgres, Redis, auth-server via Docker Compose
make health # verify all services are up
make logs # tail container logsFor local (non-Docker) development:
go mod download
# edit config.yaml with local DB/Redis URLs
go run cmd/auth-server/main.go# Build
go build -o bin/auth-server ./cmd/auth-server/main.go
make build-prod # production Docker image
# Run
make start # Docker Compose (recommended)
go run cmd/auth-server/main.go # local run
# Test
go test ./... # all tests
go test -v -cover ./... # with verbose output and coverage
make test-coverage # coverage report (minimum 80%)
go test -v ./internal/services/ # single package
go test -v ./internal/handlers/tests/
# Code quality
go fmt ./... # format
go vet ./... # static analysis
make lint # golangci-lint
make security # gosec security scanFour-layer pattern:
HTTP Handlers (internal/handlers/)
↓
Services (internal/services/)
↓
Repositories (internal/repo/gorm/)
↓
Database PostgreSQL + Redis
cmd/auth-server/main.go # entry point — server init, routes, graceful shutdown
config/config.go # Viper config loader
internal/handlers/ # Gin HTTP handlers (one file per domain)
internal/services/interfaces.go # service interfaces — read before modifying services
internal/services/ # business logic implementations
internal/repo/gorm/ # GORM repository implementations
internal/models/models.go # all GORM entity definitions
internal/middleware/middleware.go # CORS, rate limiting, auth, request ID
internal/database/database.go # Postgres connection + auto-migrations
internal/database/redis.go # Redis client setup
GET /health health check
GET /oauth/authorize authorization endpoint
POST /oauth/token token endpoint
POST /oauth/introspect token introspection
POST /oauth/revoke token revocation
GET /.well-known/openid-configuration OIDC discovery
GET /userinfo user info (protected)
/v1/tenants, /v1/users, /v1/clients management APIs (protected)
- Naming:
camelCasefor unexported,PascalCasefor exported identifiers - Errors: explicit error returns with custom error types; never swallow errors silently
- Logging: use Logrus with structured fields (
logrus.WithField(...)) - DB queries: always use parameterized queries via GORM; never build raw SQL strings from user input
- Tests: Arrange-Act-Assert pattern; name tests
TestFunctionName_Scenario_ExpectedResult - Coverage: maintain ≥ 80% test coverage per package
- Context: pass
*gin.Contextorcontext.Contextas the first parameter
Primary config file: config.yaml (loaded by Viper).
Environment variables override YAML values.
See .env.example for all supported env vars.
Critical values to set before running:
JWT_SECRET— minimum 32 charactersPOSTGRES_*— database credentialsSERVER_URL— public-facing base URL
- Define the model in
internal/models/models.go(add GORM migration if needed) - Add the repository interface + GORM implementation in
internal/repo/gorm/ - Add the service interface in
internal/services/interfaces.go - Implement the service in
internal/services/<domain>_service_impl.go - Add the HTTP handler in
internal/handlers/<domain>_handler.go - Register routes in
cmd/auth-server/main.go - Write unit tests alongside each layer