1
votes

I want to implement JWT authentication for my project since this seems to be the most simple one out of all the authentication procedures - but I don't quite understand how an User can actually login using the JWT-auth. It would be helpful if anyone could share some reading materials or provide some insights on the workflow of the login of an user using JWT. My own thoughts were somewhat along these lines:

  • The frontend sends a obtain_jwt request to the backend via drf api
  • The api returns a token in json format, if username and password were provided

It's from here I don't understand what needs to done going forward. Does the backend need to do anything else to complete the authentication/login process? Do I need to do anything else with DRF Permissions?

If this completes the login process, then there is something else which bugs me. For example, I have an APIView LoginView which has a post method to handle the login process. Now, does the frontend need to call the obtain_jwt function to get the function and then do another post-method to the LoginView? Or is there a way to return the json-web-token from that LoginView?

It would be really helpful if someone could answer these questions for me or provide some reading materials which would help me better understand the total workflow for this login process. Thanks.

Edit: My login process is being made to handle a facebook login - just to let the viewer know :)

1

1 Answers

1
votes

It's not that complicated after its explained to you. General workflow is:

  • Client sends a username and password with a POST request via javascript(ajax).
  • DRF receives it, authenticates and return a token to the client in json format.
  • Client receives the token and stores it. Token is stored on the header of ajax setup, so all subsequent calls in this app have the token in the header.
  • Now just make regular api calls, and authetication is submitted automatically through the header that DRF reads and accepts.

See this.