@@ -25,6 +25,14 @@ def add_claims_to_access_token(user):
25
25
return {'roles' : user .roles }
26
26
27
27
28
+ # This method will also get whatever object is passed into the
29
+ # create_access_token method, and let us define what the identity
30
+ # should be for this object
31
+ @jwt .user_identity_loader
32
+ def user_identity_lookup (user ):
33
+ return user .username
34
+
35
+
28
36
@app .route ('/login' , methods = ['POST' ])
29
37
def login ():
30
38
username = request .json .get ('username' , None )
@@ -38,17 +46,10 @@ def login():
38
46
# We can now pass this complex object directly to the
39
47
# create_access_token method. This will allow us to access
40
48
# the properties of this object in the user_claims_loader
41
- # function. Because this object is not json serializable itself,
42
- # we also need to provide a way to get some which is json
43
- # serializable and represents the identity of this token from
44
- # the complex object. We pass a function to the optional
45
- # identity_lookup kwarg, which tells the create_access_token
49
+ # function, and get the identity of this object from the
50
+ # user_identity_loader function.
46
51
# function how to get the identity from this object
47
- access_token = create_access_token (
48
- identity = user ,
49
- identity_lookup = lambda u : u .username
50
- )
51
-
52
+ access_token = create_access_token (identity = user )
52
53
ret = {'access_token' : access_token }
53
54
return jsonify (ret ), 200
54
55
0 commit comments