Building and testing nextjs systems
- Uses requests to fetch JWKS dynamically — real-time verification.
- Verifies signature, aud, and iss claims.
- Skips auth for known public views (e.g., login, static files).
- Logs detailed events for debugging.
- Automatically creates users if they don’t exist.
- Elevates admin users based on an allowlist.
- Performance: JWKS is fetched on every request
- Insecure JWT audience handling
You're decoding the token without verifying signature, then trusting the aud claim for the actual decode.
- No check on token azp, scp, or email claims
- Missing logging on critical auth outcomes
- Unsafe header reliance
- Potential for split(" ", 1) to throw error
- No fallback if JWKS fails
- No documentation
- Add Django settings for toggling the middleware on/off in dev.
- Track how many times JWKS fails or add Sentry monitoring.
- Rotate RSA keys with caching refresh (in case Okta rotates).