Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement google and facebook oauth2 in django rest framework ? #853

Closed
ahmedosama5200 opened this issue Jul 25, 2020 · 9 comments
Closed
Labels

Comments

@ahmedosama5200
Copy link

ahmedosama5200 commented Jul 25, 2020

I went through the documentation for a way to implement oauth2 using google and facebook providers but can't find anything. I am confused, what is this library really about ?

@bastbnl
Copy link
Contributor

bastbnl commented Jul 25, 2020

Do you want to enable people to login using a Google or a Facebook account on your site? Check django-allauth.

@ahmedosama5200
Copy link
Author

I am not sure but django-allauth doesn't work with django rest framework.

@ahmedosama5200
Copy link
Author

I have gone through documentation, they didn't even talk about how to use it with rest. also this `one and this one are not maintained any more. Any solutions ?

@bastbnl
Copy link
Contributor

bastbnl commented Jul 26, 2020

I don't know what you're trying to achieve here, but let me describe what I did on brwnppr.com and maybe it helps.

I wanted to build an application that allows users to login to the application using a social account, like Google and LinkedIn or an email account. This application is based on a REST API, which is consumed via OAuth2. I was struggling with the same thought and the solution I used was basically simpler.

To my understanding you're using Bearer tokens to communicatie with the application. The OAuth dance to Google or LinkedIn enables my application to perform requests to Google or LinkedIn using the token that's linked to the users' account, so you're invoking requests on behalf of that user. Those tokens are intended to be used with Google or LinkedIn and are linked to the Google and LinkedIn accounts.

The idea is to setup a local account on your Django application, using the data shared by the OAuth provider, which - for you - is Google or Facebook. django-allauth can safely setup and populate the user accounts on your Django application using the data provided by the social provider. Then, when you want to consume the OAuth API of the Django application you're developing, you are connecting to an authorization page hosted by your Django application. This authorization page (see: https://django-oauth-toolkit.readthedocs.io/en/latest/tutorial/tutorial_01.html) enables the user to login using their Google or LinkedIn account via the authorization page on your Django application and the OAuth dance to your application gets you the tokens needed for the API provided by your Django application.

Does this make sense?

@ahmedosama5200
Copy link
Author

Thanks for your reply
I have decoupled app, django rest framework for backend, and multiple clients on the front end (angular, android, ios)
The flow of authentication should go like this, the client signs in with google or facebook, gets an id_token that will be sent to backend. on the backend, the token is verified and exchanged for user's email, name, etc..., then a jwt token is generated and sent to the client, which is attached to all future requests.
I checked django allauth and it doesn't have such functionality, I think

I was previously working with nodejs and this process can be automated using passportjs library which is very well maintained and supported by nodejs community.

I can do this myself using a couple of different libraries, but I am trying to save myself some time and effort by finding a package that does this for me.

@professorhaseeb
Copy link
Member

professorhaseeb commented Aug 20, 2020

I use this for social oauth2 in DRF, works like a charm
https://github.com/RealmTeam/django-rest-framework-social-oauth2

Doesn’t work as expected... use django-allauth

@sorenwacker
Copy link

That seems to be written for django 1. Is it still working?

@rganowski
Copy link

In an issue for django-rest-framework-social-oauth2 I've just read that:

This lib is not maintained anymore. Use https://github.com/wagnerdelima/drf-social-oauth2 instead

@auvipy auvipy closed this as completed Oct 23, 2021
@niko-chaffinchicas
Copy link

@bastbnl What you described above sounds like something I'm trying to accomplish. It sounds like that configuration involves configuring django-allauth to redirect the user to the authorization page provided by django-oauth-toolkit, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants