The Authorization Server configuration system has been migrated from environment variables to YAML-based configuration using Viper. This provides better organization, validation, and easier management of configuration settings.
export DATABASE_URL="postgres://authuser:password@localhost:5432/authdb?sslmode=disable"
export JWT_SECRET="your-super-secret-jwt-key-minimum-32-characters-long"
export PORT="8080"
export GIN_MODE="release"
# ... and many more environment variablesCreate a config.yaml file in your project root:
# Authorization Server Configuration
# Database configuration
database:
url: "postgres://authuser:password@localhost:5432/authdb?sslmode=disable"
# Redis configuration
redis:
url: ""
# Server configuration
server:
url: "http://localhost:8080"
port: "8080"
gin_mode: "release"
# JWT configuration
jwt:
secret: "your-super-secret-jwt-key-minimum-32-characters-long"
# Security configuration
security:
bcrypt_cost: 12
access_token_duration: 3600 # seconds
refresh_token_duration: 2592000 # seconds (30 days)
authorization_code_duration: 600 # seconds (10 minutes)
# CORS configuration
cors:
allowed_origins: "*"
allowed_methods: "GET,POST,PUT,DELETE,OPTIONS"
allowed_headers: "Origin,Content-Type,Accept,Authorization"
# Rate limiting configuration
rate_limit:
requests_per_minute: 60
# Logging configuration
logging:
level: "info"
format: "json"The application will search for the configuration file in the following locations (in order):
- Current directory (
./config.yaml) - Config subdirectory (
./config/config.yaml) - System config directory (
/etc/auth-server/config.yaml)
Environment variables can still be used to override YAML configuration values. Viper automatically maps environment variables to configuration keys using the following pattern:
- YAML:
database.url→ Environment:DATABASE_URL - YAML:
server.port→ Environment:SERVER_PORT - YAML:
jwt.secret→ Environment:JWT_SECRET
| YAML Path | Environment Variable | Description |
|---|---|---|
database.url |
DATABASE_URL |
PostgreSQL connection string |
redis.url |
REDIS_URL |
Redis connection string |
server.url |
SERVER_URL |
Server base URL |
server.port |
SERVER_PORT |
Server port |
server.gin_mode |
SERVER_GIN_MODE |
Gin framework mode |
jwt.secret |
JWT_SECRET |
JWT signing secret |
security.bcrypt_cost |
SECURITY_BCRYPT_COST |
Bcrypt hashing cost |
security.access_token_duration |
SECURITY_ACCESS_TOKEN_DURATION |
Access token duration (seconds) |
security.refresh_token_duration |
SECURITY_REFRESH_TOKEN_DURATION |
Refresh token duration (seconds) |
security.authorization_code_duration |
SECURITY_AUTHORIZATION_CODE_DURATION |
Auth code duration (seconds) |
cors.allowed_origins |
CORS_ALLOWED_ORIGINS |
CORS allowed origins |
cors.allowed_methods |
CORS_ALLOWED_METHODS |
CORS allowed methods |
cors.allowed_headers |
CORS_ALLOWED_HEADERS |
CORS allowed headers |
rate_limit.requests_per_minute |
RATE_LIMIT_REQUESTS_PER_MINUTE |
Rate limit per minute |
logging.level |
LOGGING_LEVEL |
Log level |
logging.format |
LOGGING_FORMAT |
Log format |
- Better Organization: Hierarchical structure makes configuration easier to understand
- Comments: YAML supports comments for documentation
- Type Safety: Better handling of different data types
- Validation: Easier to validate configuration structure
- Version Control: Configuration files can be versioned and tracked
- Environment Specific: Different config files for different environments
# config.yaml
server:
gin_mode: "debug"
logging:
level: "debug"
format: "text"# config.yaml
server:
gin_mode: "release"
logging:
level: "info"
format: "json"
security:
bcrypt_cost: 14The application still supports .env files for backward compatibility. The loading order is:
- YAML configuration file
- Environment variables (override YAML values)
.envfile (if present)
If the configuration file is not found, the application will:
- Display a warning message
- Use default values for all configuration options
- Continue running normally
If the configuration file exists but contains errors:
- The application will fail to start
- Display a detailed error message
- Exit with a non-zero status code
- Create
config.yamlfile with your current configuration - Test the application with the new configuration
- Update deployment scripts to use YAML configuration
- Update documentation and README files
- Remove old environment variable exports (optional)
- Update CI/CD pipelines if necessary