freeBeerTomorrow
freeBeerTomorrow

Reputation: 353

How do I authenticate users with Django REST framework and React.js frontend?

I am making a website with django rest in the backend and react.js in the frontend. This will be my first time using a front end framework with django. I am using django-allauth for social auth on the backend (facebook/twitter/google).

Once the user is signed in through a web session (using allauth) via a 3rd party provider (facebook) how do I pass that data to my react app?

Do I grab the facebook token, authenticate it, then generate an oauth2/jwt token and store that somehow? Is there some boilerplate/code that will save me time on this. I don't want to reinvent the wheel here.

Many thanks!

Upvotes: 3

Views: 3589

Answers (2)

jamstooks
jamstooks

Reputation: 1525

This is an old question, but I thought I'd chime in for anyone reading this now...

As long as you set up rest_framework.authtoken you should be able to authenticate with DRF with a variety of backends.

If you're using Redux, you might consider a simple npm package that does all the groundwork already: drf-redux-auth. At the very least, it might provide the "boilerplate" you're looking for.

Upvotes: 0

Windsooon
Windsooon

Reputation: 7110

After you get the token, you can store it in cookies(or keychain if you developing an IOS app) than put the token in your request header then make a request to your server like:

curl -H "Authorization: bearer your_access_token" -A "ChangeMeClient/0.1 by YourUsername" http://your_server/your_api

This may help Authorizing a request

Upvotes: 1

Related Questions