Security Best Practices
OAuth 2.0 authentication and authorization for the Oten ecosytem.
Transport Security
HTTPS Requirements
Production: Must use
https://for all redirect URIsDevelopment: Can use
http://localhostonlyUse TLS 1.2 or higher
CSRF Protection
State Parameter
The state parameter prevents CSRF attacks.
Implementation:
Generate random state value
Store in session
Include in authorization URL
Validate on callback
Requirements:
Minimum 128 bits entropy
Cryptographically random
Single-use
Time-limited (5-10 minutes)
PKCE
When required
PKCE is mandatory for:
Single Page Applications (SPAs)
Mobile applications
Any public client
How it works
Generate code verifier (43-128 random characters)
Create code challenge (SHA-256 hash of verifier)
Send challenge with authorization request
Send verifier with token exchange
Token security
Storage
Web App
Server-side session
Browser localStorage
SPA
Memory only
localStorage/sessionStorage
iOS
Keychain
UserDefaults
Android
EncryptedSharedPreferences
SharedPreferences
Best practices
Use short-lived access tokens (15-60 min)
Implement refresh token rotation
Always use HTTPS
Include tokens in
AuthorizationheaderNever log tokens
Client secret management
Never:
Commit to version control
Embed in client-side code
Log in application logs
Share via email/chat
Store in plain text
Secure storage
Development
Environment variables (.env)
Production
Secret management (Vault, AWS secrets manager)
Rotation policy
Regular: Every 90 days
Incident: Immediately upon compromise
Automated: Use secret rotation tools
Monitoring
Security events to monitor
Failed authentication attempts
Unusual token usage patterns
Scope escalation attempts
Geographic anomalies
Rapid token refresh
Incident response
Detect and assess
Revoke compromised credentials
Investigate logs
Rotate secrets
Notify affected users
Document incident
Compliance
Data protection
Implement data minimization
Provide clear privacy policies
Enable user consent management
Support data deletion requests
Maintain audit logs
Regulations
GDPR (EU) - Data protection
CCPA (California) - Consumer privacy
HIPAA (Healthcare) - Health information
PCI DSS (Payment) - Card data security
Resources
External guidelines
Tools
Last updated