|
13 | 13 | # function is used to actually generate the token |
14 | 14 | @app.route('/login', methods=['POST']) |
15 | 15 | def login(): |
16 | | - if request.is_json: |
17 | | - params = request.get_json() |
18 | | - if 'username' in params.keys() and 'password' in params.keys(): |
19 | | - if params['username'] != 'test' or params['password'] != 'test': |
20 | | - return jsonify({"msg": "Bad username or password"}), 401 |
21 | | - else: |
22 | | - return jsonify({"msg": "Missing auth parameters"}), 401 |
23 | | - |
24 | | - # Identity can be any data that is json serializable |
25 | | - ret = {'access_token': create_access_token(identity=params['username'])} |
26 | | - return jsonify(ret), 200 |
27 | | - else: |
| 16 | + if not request.is_json: |
28 | 17 | return jsonify({"msg": "Missing auth"}), 401 |
| 18 | + params = request.get_json() |
| 19 | + if 'username' in params and 'password' in params: |
| 20 | + if params['username'] != 'test' or params['password'] != 'test': |
| 21 | + return jsonify({"msg": "Bad username or password"}), 401 |
| 22 | + else: |
| 23 | + return jsonify({"msg": "Missing auth parameters"}), 401 |
| 24 | + |
| 25 | + # Identity can be any data that is json serializable |
| 26 | + ret = {'access_token': create_access_token(identity=params['username'])} |
| 27 | + return jsonify(ret), 200 |
| 28 | + |
| 29 | + |
29 | 30 |
|
30 | 31 | # Protect a view with jwt_required, which requires a valid access token |
31 | 32 | # in the request to access. |
|
0 commit comments