Quiz Space

Modern Application Development II · End Term · 13 Apr 2025 · January 2025 term · Set QDD1

Question 30: Consider the following flask app implemented with JWT. T…

Question 30

+3 marksOne correct option

Consider the following flask app implemented with JWT. The application running on http://127.0.0.1:5000 and the user logs in using the /login endpoint.

Read the following questions and select the correct statement.

python
app = Flask(__name__)
app.config["JWT_SECRET_KEY"] = "supersecretkey"
jwt = JWTManager(app)
@app.route("/login", methods=["POST"])
def login():
user = {"username": "student", "role": "student"}
access_token = create_access_token(identity=user)
return jsonify(access_token=access_token)
@app.route("/protected", methods=["GET"])
@jwt_required()
def protected():
current_user = get_jwt_identity()
if current_user.get("role") != "admin":
return jsonify({"message": "Forbidden: Insufficient permissions"}),
403
return jsonify(message=f"Hello, {current_user['username']}!")
app.run()

Based on the above data, answer the given subquestions.

What will be the result of the following fetch request.

javascript
fetch("http://127.0.0.1:5000/protected", {
method: "GET",
headers: {
"Authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVJ9.."
}
})
.then(response => {
if (response.status === 403) {
throw new Error("403 Forbidden: Insufficient permissions");
}
return response.json();
})
.then(data => console.log("Protected Route Response:", data))
.catch(error => console.error("Error:", error));
  1. A
  2. B
  3. C
  4. D
Show answer

Correct answer

  • D

Question 30 of 32 in the IIT Madras BS Modern Application Development II (MAD 2) End Term paper sat on 13 Apr 2025, in the January 2025 term (IIT M DIPLOMA AN EXAM QDD3 13 Apr 2025). It carries 3 marks.

More questions from this paper

  1. Q1Which of the following statements is true regarding the "this" keyword in JavaScript?
  2. Q2Which of the following correctly describes the lifecycle of a Vue.js component?
  3. Q3Consider the below JavaScript program. What will be the output of the above program?
  4. Q4Which of the following is NOT a common performance metric measured by Google Lighthouse?
  5. Q5Which of the following is a key difference between Web Sockets and Server-Sent Events (SSE)?
  6. Q6Which HTTP method is typically used for sending webhook notifications?
  7. Q7Figure question
  8. Q8Consider the below JavaScript program. What will be the output of the above program?
  9. Q9Consider the below Vuex store configuration: If the addItemAsync action is dispatched with the item 'Vue.js', what will…
  10. Q10Consider the below Vue app. What happens when the user clicks "Go to Foo"?
  11. Q11Consider the following Vue component using slots: How would you use this component to provide custom title and content …
  12. Q12Consider the following Vue component. Which of the following is the correct way to use this component with a scoped slo…
  13. Q13Consider the following JavaScript program, and predict the output, if executed.
  14. Q14Consider the following Flask application (server.py): server.py The application runs on http://localhost:5000.\ A clien…
  15. Q15Consider the following JavaScript code. When the function is called, what will be returned if the request gives a 200 O…
  16. Q16Consider the following JavaScript code snippet. If the code is run on the browser, what will be the output on the conso…
  17. Q17Which of the following options is the correct sequence of steps in JWT authentication?
  18. Q18Consider the below CORS enabled flask app. If a Vue.js frontend (simulation given below) at “http://localhost:3000” tri…
  19. Q19Consider the below Vuex setup. What is logged to the console immediately after dispatching the action?
  20. Q20Figure question
  21. Q21Consider the following Flask application (server.py) and an HTML file named index.html: server.py index.html If you ope…
  22. Q22Consider the following Vue apps in script.js and the index.html file. script.js index.html What will be rendered on the…
  23. Q23Consider the following Vue App and the HTML document given below. index.html script.js What will be the output on the b…
  24. Q24Consider the below flask implementation with JWT based authentication. If a Vue.js client sends this request 15 seconds…
  25. Q25Which of the following is/are the correct usage of “v-for” directive in VueJS?
  26. Q26Which of the following are advantages of using GraphQL over REST?
  27. Q27Which of the following statements are true regarding event loop in JavaScript?
  28. Q28Consider the below Vuex store configuration. And the below Vue component: What will be displayed in the placeholder “{{…
  29. Q29Consider the following flask app implemented with JWT. The application running on http://127.0.0.1:5000 and the user lo…
  30. Q31What will be rendered on the browser if the application is loaded on the browser for the first time?
  31. Q32What will be rendered on the browser for the given value of localStorage?