8
8
jwt = JWTManager (app )
9
9
10
10
11
- # A user object that we will load our tokens
11
+ # A demo user object that we will use in this example
12
12
class UserObject :
13
13
def __init__ (self , username , roles ):
14
14
self .username = username
15
15
self .roles = roles
16
16
17
17
# An example store of users. In production, this would likely
18
- # be a sqlalchemy instance or something similiar
18
+ # be a sqlalchemy instance or something similar
19
19
users_to_roles = {
20
20
'foo' : ['admin' ],
21
21
'bar' : ['peasant' ],
@@ -24,7 +24,7 @@ def __init__(self, username, roles):
24
24
25
25
26
26
# This function is called whenever a protected endpoint is accessed.
27
- # This should return a complex object based on the token identity.
27
+ # This should return an object based on the token identity.
28
28
# This is called after the token is verified, so you can use
29
29
# get_jwt_claims() in here if desired. Note that this needs to
30
30
# return None if the user could not be loaded for any reason,
@@ -53,14 +53,14 @@ def custom_user_loader_error(identity):
53
53
# Create a token for any user, so this can be tested out
54
54
@app .route ('/login' , methods = ['POST' ])
55
55
def login ():
56
- username = request .json .get ('username' , None )
56
+ username = request .get_json () .get ('username' , None )
57
57
access_token = create_access_token (identity = username )
58
58
ret = {'access_token' : access_token }
59
59
return jsonify (ret ), 200
60
60
61
61
62
62
# If the user_loader_callback returns None, this method will
63
- # not get hit , even if the access token is valid. You can
63
+ # not be run , even if the access token is valid. You can
64
64
# access the loaded user via the ``current_user``` LocalProxy,
65
65
# or with the ```get_current_user()``` method
66
66
@app .route ('/admin-only' , methods = ['GET' ])
0 commit comments