authentication from mobile to backend django

Viewed 2661

Good day everyone. I am stumped at the moment and would appreciate some guidance. I feel like I am a great googler to usually find my answers or resources but for the life of me I can't seem to find any good learning material on JSON requests and responses.

So I took a course that builds a 3 part app. Web app with Django, and 2 mobile apps that make API calls to it. The instructor uses Facebook authentication from the mobile apps and I am trying to set up the apps for username and login and a registration page as well.

I have django models setup and and can make users from the web app but I can't seem to wrap my head around how to make JSON calls from app to Django. When I search for possible terms like authenticate django I get results that talk about only django usage.

Does anyone have some tips or links to resources that would help me understand the login process better. I realize that almost every app has a login which is why I'm surprised that I can't find any good learning material on how its done. Or I'm just searching for wrong keywords.

Any help would be great thanks.

1 Answers

It's really a general question, But i give you a brief on how mobile and django server should interact with each other:

  • First of all, in your situation I really suggest to use django rest framework, Because of it's rich modules and functionallity like serializers, routers and ... read more about it from origin documentation here.

  • For authentication system, You should use a token based system (or session). I suggest use one of django suggested token based solutions for that. In my case i really suggest to use django-restframework-jwt library (JSON Web Token Authentication support for Django REST Framework). so whenever you want to send a request to mobile you should provide that token (based on token authentication backend you choose) in your headers of request.

  • And for login and register you should create APIViews that takes user input, then register or authenticated it with backend and then gives user the generated token for future requests.

  • And for social auth system like facebook, the main concept is to redirect user from app to facebook oauth links, which if the user authenticate in his facebook will redirect you redirect url of your backend server, then you should capture that request in callback, fetch data and create or get the user and generate the token for that user and return it. so that for furture requests, by sending token to server, server will know that which user is sending this request and handle response properly for that.

  • And if you want to create a login with mobile, then you need to setup APIs for login, register with django rest which is really easy and you can learn from it here.

Related