I am trying to integrate Social Authentication in my DRF backend. I decided to go with python-social-auth. If I serve my social login through Django (and an HTML view), I can see my login in successful. I also figured that I can redirect after successful social authentication as outlined here.
Until now, my frontend (a Nuxt app) was using DRF tokens. Even though:
Is it possible for me to somehow manage to redirect a successfully authenticated user to the frontend with the associated and valid DRF token as a query parameter?
You can, it's not trivial, tho. It's possible because the mechanism to retrieve URLs (success or errors ones) is delegated to strategies setting() method, which in the end invokes get_setting() on final implementations. This method you can override to add your custom logic.
These steps should get you on the road:
Define a custom strategy
from social_django.strategy import DjangoStrategy
class CustomStrategy(DjangoStrategy):
def get_setting(self, name):
if name == 'LOGIN_REDIRECT_URL':
token = get_drf_token()
return f'/?toke={token}'
else:
return super().get_setting(name)
Point your SOCIAL_AUTH_STRATEGY settings to this new strategy (import path syntax)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With