st4lk / django-rest-social-auth

OAuth signin with django rest framework
MIT License
521 stars 122 forks source link

How to continue pipeline #122

Closed jd-solanki closed 4 years ago

jd-solanki commented 4 years ago

Hi, I have am using @partial to pause the pipeline but I don't know how to resume it.

I have checked your example project but I can't anything related to continuing pipeline.

To which URL I should make request. Is it post/get method.

Actually, I have tried various ways before creating this issue like adding social_django urls and making post request to complete view but I am unable to set received data from user e.g. email.

@api_view(["GET","POST"])
@permission_classes([AllowAny,])
def require_email(request):
    strategy = load_strategy()
    partial_token = request.GET.get('partial_token')
    partial = strategy.partial_load(partial_token)

    if request.method == 'POST':
        request.session['email'] = request.data.get('email')

        redirect_url = reverse('social:complete', kwargs={'backend': partial.backend}) + "?partial_token=" + partial_token

        return redirect(redirect_url)
    else:
        return Response({'error': "Email wasn't provided by oauth provider", 'continue_url': f"{reverse('require_email')}?partial_token={partial_token}", 'token': partial_token}, status=202)
@partial
def check_email(strategy, backend, request, response, is_new, details, user=None, *args, **kwargs):

    if user and user.email:
        return

    elif is_new and not details.get('email'):
        email = strategy.session_get('email')

        if email:
            details['email'] = email
        else:
            current_partial = kwargs.get('current_partial')

            return strategy.redirect(f"{reverse('require_email')}?partial_token={kwargs.get('current_partial').token}")

So, @st4lk can you please help me out.

~ Regards

st4lk commented 4 years ago

Hi @jd-0001

Current package doesn't provide means for resuming paused pipeline.

There is an attempt to do it: https://github.com/st4lk/django-rest-social-auth/pull/105. I haven't checked it fully yet, will try to do it soon.

BTW, PRs are warmly welcome!

jd-solanki commented 4 years ago

Hi, @st4lk Have you tried. After the digging of 3 days in every used package till social-core somehow I managed to resume the pipeline but still, I am not able to complete the flow.

After completion of the pipeline I get redirected to account/profiles(account is my app url prefix) then I updated SOCIAL_AUTH_LOGIN_REDIRECT_URL but in that view I if I access request.user it is still anonymous. I don't know if a user is logged in yet or not. How to get both user and token so I can send back response to my front-end with user and token?

Any Idea?

I hope you are safe during this days :house:

~ Regards

jd-solanki commented 4 years ago

I have fixed this. There was some config related to:

SOCIAL_AUTH_FORCE_EMAIL_VALIDATION
SOCIAL_AUTH_EMAIL_VALIDATION_URL
SOCIAL_AUTH_LOGIN_REDIRECT_URL
SOCIAL_AUTH_EMAIL_VALIDATION_FUNCTION

after configuring them, I was to continue pipeline