Question 30
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.
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.
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));