Generate new tokens periodically and phase out old ones:
Copy
async function rotateToken() { // Generate new token const response = await fetch('https://api.screenshotly.app/api/keys/generate', { method: 'POST', headers: { 'Authorization': `Bearer ${currentToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ name: 'Production Token', expiresIn: 30, // 30 days }), }); const { apiKey } = await response.json(); // Update your configuration with the new token // Then phase out the old token after ensuring the new one works}
✅ Use environment variables for token storage
✅ Rotate tokens regularly (every 30-90 days)
✅ Monitor token usage for suspicious activity
✅ Use different tokens for different environments
✅ Implement proper error handling
✅ Have a token rotation strategy
✅ Keep tokens out of version control
✅ Revoke compromised tokens immediately