Skip to content

Commit 3596b6b

Browse files
authored
Merge pull request #75 from reiven/master
Fix for #74 do not fail with empty request to /auth
2 parents 8261502 + f42956d commit 3596b6b

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

examples/simple.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,20 @@
1313
# function is used to actually generate the token
1414
@app.route('/login', methods=['POST'])
1515
def login():
16-
username = request.json.get('username', None)
17-
password = request.json.get('password', None)
18-
if username != 'test' or password != 'test':
19-
return jsonify({"msg": "Bad username or password"}), 401
16+
if not request.is_json:
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
2024

2125
# Identity can be any data that is json serializable
22-
ret = {'access_token': create_access_token(identity=username)}
26+
ret = {'access_token': create_access_token(identity=params['username'])}
2327
return jsonify(ret), 200
2428

29+
2530

2631
# Protect a view with jwt_required, which requires a valid access token
2732
# in the request to access.

0 commit comments

Comments
 (0)