Home > Software design >  dictionary in flask_jwt_extended create_access_token
dictionary in flask_jwt_extended create_access_token

Time:02-14

How can i use dictionary in token identity with flask_jwt_extended. Any suggestions for pass multiple values in token?

create_access_token(identity=????)

Thanks

CodePudding user response:

Yes this is totally can be done by passing a dictionary like:

create_access_token(identity= {"name":"Hello", "age":35} )

and this would work by implementing a callback function decorated with user_identity_loader. The callback function should take one argument and returns JSON string:

jwt = JWTManager(app)

import json 

@jwt.user_identity_loader
def user_maker(obj):
    return json.dumps(obj)

read more

  • Related