Bird
0
0

Consider this simplified server response code snippet handling a refresh token request:

medium📝 Predict Output Q13 of 15
Rest API - Authentication and Authorization
Consider this simplified server response code snippet handling a refresh token request:
if refresh_token == valid_token:
    access_token = generate_new_token()
    return {"access_token": access_token, "status": 200}
else:
    return {"error": "Invalid refresh token", "status": 401}
What will be the output if refresh_token is invalid?
A{"access_token": "newtoken123", "status": 200}
B{"error": "Invalid refresh token", "status": 401}
CSyntaxError
D{"status": 200}
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the condition for refresh token validity

    If the refresh token matches the valid token, a new access token is generated and returned with status 200.
  2. Step 2: Check the else branch for invalid token

    If the token is invalid, the code returns an error message with status 401.
  3. Final Answer:

    {"error": "Invalid refresh token", "status": 401} -> Option B
  4. Quick Check:

    Invalid token returns error 401 [OK]
Quick Trick: Invalid token triggers error response 401 [OK]
Common Mistakes:
  • Assuming new token is returned even if invalid
  • Confusing status codes 200 and 401
  • Expecting syntax errors from valid code

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes