4

I understand that Flask JWT gives us the /auth endpoint. Once a user successfully logs in, an access token is assigned and the logged in user can be stored in Flask JWT's current_identity. What I'm wondering is can I also return the User Json back to my client in the same /auth endpoint? Or does it have to be a separate request?

This is for a mobile rest-api, using Flask-Restful. Right now, I have a user log in. The login route (/auth) returns the access token to the client, and then I use the token to get the User Json in a separate request, but I feel like I should be able to condense this into the same request.

Any tips are appreciated :)

IDEA: Can I create an auth resource via flask-restful and specify exactly what I want it to return? (the token for the server and the user json to the client?)

user7804097
  • 308
  • 1
  • 3
  • 17

1 Answers1

2

Flask-JWT has been abandoned for quiet a while now. I would suggest checking out Flask-JWT-Extended instead as an alternative that is still actively maintained (full disclosure, I'm the author of that extension).

In Flask-JWT-Extended you create your own endpoint instead of having the extension create one for you, so you can return whatever data you want there. Here is an example of this in action: http://flask-jwt-extended.readthedocs.io/en/latest/basic_usage.html

vimalloc
  • 3,869
  • 4
  • 32
  • 45
  • thanks for the suggestion. Would I have to change everything to switch over? Or are the naming conventions the same, like current_identity for example. I want to after reading your answer, but changing all my api code sounds tedious :[ – user7804097 Jun 08 '18 at 04:27
  • There will be some changes for sure, but it shouldn't be too crazy. Here is the documentation for setting up and using a `current_user` with flask-jwt-extended: http://flask-jwt-extended.readthedocs.io/en/latest/complex_objects_from_token.html. – vimalloc Jun 08 '18 at 04:37