Session Cookies, JWTs and OAuth — Concept Check
Questions on Session Cookies, JWTs and OAuth. Three mechanisms with different trade-offs. The real question is not which is more modern, it is whether you can revoke a credential before it expires.
Questions in this quiz
8 questions on Session Cookies, JWTs and OAuth — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A web application uses session cookies for authentication. What happens when a user logs out?
- AThe session remains active until it naturally expires.
- BThe session is revoked after a delay, logging the user out eventually.
- CThe session cookie is deleted but the session remains active on the server.
- DThe session is immediately revoked and the user is logged out everywhere.
2.A company uses JWTs for authentication. An employee is fired at 10:00 AM. What issue might arise?
- AThe employee's token is revoked immediately.
- BThe employee's token is automatically deleted.
- CThe employee's token becomes invalid due to a role change.
- DThe employee's token remains valid until it expires.
3.What is a common approach to mitigate the non-revocability of JWTs?
- AEncrypt JWTs to prevent unauthorized access.
- BUse JWTs only for browser sessions.
- CStore JWTs in a database for tracking.
- DImplement short expiry times with refresh tokens.
4.In the OAuth 2.0 Authorization Code flow, why is the client secret not sent to the browser?
- ATo prevent it from being intercepted and misused.
- BTo reduce the size of the request payload.
- CBecause the browser cannot handle secrets.
- DBecause it is not needed for token exchange.
5.A developer claims that sessions do not scale well. What is a counterargument?
- ASessions are only suitable for small applications.
- BSessions require complex infrastructure to scale.
- CRedis can handle session scaling trivially for most products.
- DSessions inherently have performance issues at scale.
6.Why should algorithms be specified when decoding a JWT?
- ATo avoid using the wrong secret key.
- BTo speed up the decoding process.
- CTo prevent 'alg': 'none' forgeries in real libraries.
- DTo ensure the token is encrypted properly.
7.Why is OAuth often used with a provider like Auth0 or NextAuth?
- ATo simplify the implementation and handle common issues.
- BTo avoid using JWTs altogether.
- CTo prevent the need for browser-side code.
- DTo ensure tokens are always encrypted.
8.What is a potential drawback of using JWTs for browser sessions?
- AJWTs cannot be revoked before they expire.
- BJWTs automatically log out users on role change.
- CJWTs require a database lookup for each request.
- DJWTs are always encrypted, adding overhead.