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

Minimal example for SPA implementation of social login #147

Open
nimame opened this issue Sep 20, 2020 · 3 comments
Open

Minimal example for SPA implementation of social login #147

nimame opened this issue Sep 20, 2020 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed

Comments

@nimame
Copy link

nimame commented Sep 20, 2020

First of all many thanks for the great work! I am dedicated to use this package for project I'm working on. However, I have spent a few days now trying to understand the code of allauth and this package in order to build a simple social auth REST API for a SPA app (Angular) and I just fail to understand how a social login (with Google or Azure) works using the SocialLoginView (in /allauth/account/views.py). This view seems to expose a POST endpoint expecting an access_token and/or code in its body. But how do I get those in the first place? I would appreciate if someone could post / point me to a minimal example that covers the complete flow from hitting a "Login with Google" button in an SPA app (e.g. Angular, React, Vue or whatever) to receiving the data (e.g. JWT token) necessary to make requests to secured endpoints. I think the docs would greatly benefit from that too. Thanks again!

@jpaav
Copy link

jpaav commented Sep 21, 2020

After struggling to use social logins with my SPA for days, I finally figured out how the flow is supposed to work. Unfortunately I don't have example code, but I can explain what I did to setup Google OAuth2

  1. Create the OAuth2 credentials and get/make a matching link. For example, here is what the Google OAuth2 link might look like.
  2. Put that link in your SPA. When the user clicks it, the "Sign in with Google" page will open.
  3. Create a new page in your SPA that will be the callback URL. You will need to specify this URL when you set up the OAuth2 credentials. That page should take the code query parameter (or access_token) and make a POST request to the SocialLoginView or SocialConnectView endpoint.
  4. Once that post request goes through, you should have usable tokens stored in the SocialToken model.

SPA page => Google Sign in page => SPA callback page (code as query param) => REST API (code as POST data)

The setup for other providers might be a little different, but that's the gist of things.

@iMerica iMerica self-assigned this Sep 22, 2020
@iMerica iMerica added documentation Improvements or additions to documentation help wanted Extra attention is needed labels Sep 22, 2020
@iMerica
Copy link
Owner

iMerica commented Sep 22, 2020

I agree this would be very helpful. I'm not sure I have the bandwidth to add this, but PRs are welcome!

@ghost
Copy link

ghost commented Feb 2, 2021

I'm hitting #158 and downgrading djangorestframework to 3.10.2 did not fix it for me. I'm wondering if there's a good enough workaround because I'm hacking something together right now.

EDIT: it's something wrong with my versions of libraries and Pipenv.
SOLVED: yes, it was my pipenv being out of whack

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants