Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions examples/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down