Django - DRF (django-rest-framework-social-oauth2) and React creating a user
Asked Answered
S

1

9

I'm using the DRF and ReactJS and I am trying to login with Patreon using django-rest-framework-social-oauth2.

In React, I send a request to the back-end auth/login/patreon/ and I reach the Patreon OAuth screen where I say I want to login with PAtreon. Patreon then returns with a request to the back-end at accounts/profile. At this point a python-social-oauth user has also been created.

At this point I'm confused. How do I make a request to Patreon to login, create a user in the back-end, and return the session information to the react front-end so that I can include the session information in all following requests from the front-end? I don't want the returned request to be at the backend/accounts/profile, do I?

Update I now realize I can set the redirect url with LOGIN_REDIRECT_URL but still, how do I now retrieve the session id, pass it to the front-end, and include it with all requests?

Safelight answered 19/8, 2018 at 22:55 Comment(0)
O
0

Once you receive the user profile email, unique id, and other details from Patreon then create a user at the Database level.

Now after creating a user at the Database level you have to log in the user using the Django login function or any other login mechanism before redirecting the user to the frontend with a session. The redirect URL for the home/ landing page is provided by the Frontend side where they want to land the user after being successfully logged with session-id being set in cookies. Onward Frontend side can use session id in cookies for other requests.

Here is the flow:

React JS -> auth/login/patreon/ -> redirected to Patreon -> Redirected back to the Backend with user information -> Create User (DB level) -> Login user -> Redirect back to Frontend (React JS on a specific URL provided by Front end)

Odontology answered 12/1, 2022 at 13:43 Comment(1)
That means react app should be 'started' again? (Losing state)Armlet

© 2022 - 2024 — McMap. All rights reserved.