diff --git a/examples/simple.py b/examples/simple.py index 53727348..487c21c5 100644 --- a/examples/simple.py +++ b/examples/simple.py @@ -13,15 +13,20 @@ # function is used to actually generate the token @app.route('/login', methods=['POST']) def login(): - username = request.json.get('username', None) - password = request.json.get('password', None) - if username != 'test' or password != 'test': - return jsonify({"msg": "Bad username or password"}), 401 + if not request.is_json: + return jsonify({"msg": "Missing auth"}), 401 + params = request.get_json() + if 'username' in params and 'password' in params: + if params['username'] != 'test' or params['password'] != 'test': + return jsonify({"msg": "Bad username or password"}), 401 + else: + return jsonify({"msg": "Missing auth parameters"}), 401 # Identity can be any data that is json serializable - ret = {'access_token': create_access_token(identity=username)} + ret = {'access_token': create_access_token(identity=params['username'])} return jsonify(ret), 200 + # Protect a view with jwt_required, which requires a valid access token # in the request to access.