DOCTOR_DRUID
DOCTOR_DRUID

Reputation: 23

Angular 2 frontend django 2 REST framework backend user auth

I'm new to Django and JavaScript, so please forgive me if this is an obvious question.

What is the best way to authenticate users?

I can only find posts about using this which doesn't support django 2.

Thanks for your help.

Upvotes: 1

Views: 390

Answers (1)

luc
luc

Reputation: 43126

django-rest-framework provides several solutions for authentication. I recommend to read carefully the docs : http://www.django-rest-framework.org/api-guide/authentication/

I've already used Token authentication on several projects and it works fine:

You need to install the rest_framework.authtoken app in your project. This app is provided with django-rest-framework

Then you need create a token for every user. There are several ways described in the docs.

On the client side, you need to implement a login form. Your backend will check user and password and gets back the user token.

Then you can pass this token in the header of every request:

Authorization: Token value-of-the-token

Make sure to use https if you use Token authentication.

Upvotes: 1

Related Questions