Security Best Practices
🔒 Secrets Management
Never Commit Secrets
oauth.WithOAuth(mux, &oauth.Config{
JWTSecret: []byte("my-secret-key"), // Committed to git!
ClientSecret: "hardcoded-secret", // Committed to git!
})oauth.WithOAuth(mux, &oauth.Config{
JWTSecret: []byte(os.Getenv("JWT_SECRET")),
ClientSecret: os.Getenv("OAUTH_CLIENT_SECRET"),
})Environment Variables
# .env (add to .gitignore!)
JWT_SECRET=your-random-32-byte-secret-key-here
OAUTH_CLIENT_ID=your-client-id
OAUTH_CLIENT_SECRET=your-client-secret
OAUTH_ISSUER=https://yourcompany.okta.com.gitignore
🔐 JWT Secret Strength (HMAC Provider)
Minimum Requirements
Validation
Rotation
🌐 HTTPS in Production
Always Use TLS
Get Certificates
Certificate Management
🎯 Audience Validation
Why Audience Matters
Configuration
Validation
🔄 Token Caching & Expiration
Cache Behavior
Token Expiration Recommendations
🛡️ PKCE (Proof Key for Code Exchange)
Automatic Protection
No Configuration Needed
🚪 Redirect URI Security
Native Mode (Client OAuth)
Proxy Mode (Server OAuth)
🎫 Token Security
Token Storage (Client Side)
Token Transmission
🔍 Logging & Monitoring
What Gets Logged
What NOT to Log
Custom Logger for Production
🚨 Rate Limiting
Protect OAuth Endpoints
🔁 Security Headers
📋 Security Checklist
Pre-Production
Regular Maintenance
🚩 Security Incidents
Token Compromise
Suspicious Activity
📚 Additional Resources
🤝 Reporting Security Issues
Last updated
Was this helpful?