Bird
0
0

Consider this code snippet in a microservice forwarding a JWT token:

medium📝 Analysis Q13 of 15
Microservices - Authentication and Authorization
Consider this code snippet in a microservice forwarding a JWT token:
fetch('http://serviceB/api', {
  headers: { 'Authorization': req.headers['authorization'] }
})
What will happen if the original request has no Authorization header?
AThe Authorization header is set to an empty string
BService B receives an Authorization header with value 'undefined'
CThe fetch call throws an error and fails
DService B receives the request without any Authorization header
Step-by-Step Solution
Solution:
  1. Step 1: Check header forwarding code

    The code forwards req.headers['authorization'] directly as the Authorization header value.
  2. Step 2: Understand missing header behavior

    If req.headers['authorization'] is undefined, the header is omitted in fetch, so Service B gets no Authorization header.
  3. Final Answer:

    Service B receives the request without any Authorization header -> Option D
  4. Quick Check:

    Missing header means no Authorization sent [OK]
Quick Trick: Undefined header means no header sent, not 'undefined' string [OK]
Common Mistakes:
MISTAKES
  • Assuming 'undefined' string is sent as header value
  • Expecting fetch to throw error on missing header
  • Thinking header is set to empty string automatically

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Microservices Quizzes