File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed
Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change 1313# function is used to actually generate the token
1414@app .route ('/login' , methods = ['POST' ])
1515def 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
20-
21- # Identity can be any data that is json serializable
22- ret = {'access_token' : create_access_token (identity = username )}
23- return jsonify (ret ), 200
24-
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 :
28+ return jsonify ({"msg" : "Missing auth" }), 401
2529
2630# Protect a view with jwt_required, which requires a valid access token
2731# in the request to access.
You can’t perform that action at this time.
0 commit comments