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?