3

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!

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

To whom it may concern: auth tokens must be used in conjunction with https in production environments. Otherwise, anyone can sniff your client's auth token from the header.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.