Event Loop & Asynchronous I/O in Node.js
15 questions · 12 min · Medium
Test your knowledge of authentication and JSON Web Tokens in Node.js with 20 questions covering login flows, JWT structure, signing and verification, access tokens, refresh tokens, password hashing, cookies, middleware, authorization, and security best practices.
No sign-up needed · Last updated:
Score: 0 00:00
Create a free account to keep your scores and track your progress. It is optional.
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
15 questions · 12 min · Medium
B. To verify the identity of a user
Authentication verifies who a user or client is. Authorization determines what that authenticated user is allowed to access.
B. JSON Web Token
JWT stands for JSON Web Token and is a compact format for securely transmitting claims between parties.
A. Header, Payload, Signature
A JWT normally consists of a header, payload, and signature, separated by periods.
A. Claims about the token or subject
The payload contains claims such as subject identifiers, issuer information, expiration time, and application-specific data. It should not contain sensitive secrets such as plaintext passwords.
B. No, it is typically encoded rather than encrypted
A standard signed JWT provides integrity and authenticity but does not hide its payload. Sensitive information should not be placed in the payload unless an appropriate encryption mechanism is used.
A. To verify that the token has not been altered and was signed by a trusted party
The JWT signature is used to verify the integrity and authenticity of the signed token.
A. Authorization
A common pattern is to send the token in the Authorization header using the Bearer scheme.
B. Authorization: Bearer <token>
Bearer authentication commonly uses the format Authorization: Bearer followed by the access token.
B. Verify its signature and relevant claims
A server should verify the token's signature and validate relevant claims such as expiration, issuer, audience, and subject as appropriate.
A. To provide temporary credentials for accessing protected resources
An access token represents authorization to access protected resources and is commonly configured with a relatively short lifetime.
A. To obtain a new access token without requiring the user to log in again
A refresh token can be used by an authentication system to issue a new access token after the current access token expires, subject to server-side validation and policy.
B. Store passwords using a password-hashing algorithm
Passwords should be stored using a dedicated password-hashing algorithm such as Argon2id or bcrypt rather than plaintext or reversible encoding.
A. Base64 is reversible and is not a password-hashing algorithm
Base64 is an encoding scheme, not a security mechanism. Encoded data can easily be decoded.
A. HttpOnly
The HttpOnly cookie attribute prevents browser scripts from accessing the cookie through APIs such as document.cookie.
A. Secure
The Secure attribute tells the browser to send the cookie only over secure HTTPS connections, subject to browser behavior and context.
A. The token's expiration time
The exp registered claim identifies the time after which the JWT should no longer be accepted.
A. Determining whether an authenticated user has permission to perform an action
Authorization determines what an authenticated identity is permitted to access or do.
A. Authentication middleware
Authentication middleware can extract credentials, verify a JWT, and attach the authenticated identity to the request before protected route handlers execute.
A. To prevent unauthorized parties from obtaining credentials needed to forge or validate tokens
Signing credentials are sensitive secrets. They should be protected through appropriate secret-management mechanisms rather than being committed directly to source control.
A. Authentication verifies identity, while authorization determines permitted access
Authentication answers who the user is, while authorization determines what that authenticated user is allowed to access or perform.