Now the challenge is to provide the token from the server to the frontend. You would probably load the token in the HTML of the initialisation of the SPA, and then from Angular save the token client side (cookie, localStorage, etc.) so the session isn’t lost on a refresh.
If you don’t want the user to leave your app, you can open your
We used hello.js for O-Auth at the company I worked at.
You provide a shim on the Python end and get the refresh token and whatever other data needed once the user connects their social account.
We redirect them via Django to the page they attempted to access from their OAuth provider’s page.
Each user still has their own email account which is needed for the JWT, but you could assume that whatever email is in the scope of their social account is their email then use django’s functionality to create new users:
- Using Django view variables inside templates
- Django signals, how to use "instance"
- Django @csrf_exempt not working in class View
Django-allauth provides signals that let you hook into the social login process. In your case, I would recommend subscribing to the allauth.socialaccount.signals.pre_social_login signal. The code will look something like this:
from allauth.socialaccount.signals import pre_social_login
def create_jwt_token(sender, request, sociallogin, **kwargs):
# dig into the sociallogin object to find the new access token.
- Django & the "TemplateDoesNotExist" error
- Error "Could not load Boto's S3 bindings."
- Can't git-push to heroku due to "Build stream timed out"
- Celery periodic tasks not executing
- Getting scrapy project settings when script is outside of root directory