drf-social-oauth2
drf-social-oauth2 copied to clipboard
Pausing Pipeline gives 'HttpResponseRedirect' object has no attribute 'is_active'
Same issue as https://github.com/RealmTeam/django-rest-framework-social-oauth2/issues/208
If a partial pipeline is put into SOCIAL_AUTH_PIPELINE, when the pipeline function returns a redirect, the validate_token_request
of class SocialTokenGrant
will always throw an error: 'HttpResponseRedirect' object has no attribute 'is_active'.
I will look into this once I have some time! Thanks for reporting.
@exgphe I took some time to understand what you meant by this 'error'. I don't think that you guys have used this framework as it should be used. First of all you don't need to handle anything regarding the python-social-auth
library. drf-social-oauth2
will handle this for you. All you need to do to get your users registered is to follow up the steps described on the README.md file in this project.
In order to get the token you need to fire a request to the /convert_token endpoint described here: https://github.com/wagnerdelima/drf-social-oauth2#facebook-example
The URL can be found here: https://github.com/wagnerdelima/drf-social-oauth2/blob/f59c541f6597cea5aaf0028d9695b5d3ce035640/drf_social_oauth2/urls.py#L18
The /convert_token API works. The problem is that this API creates new users automatically in the database if the user of the given token does not exist. This is not suitable for many registration processes. For example, it is quite common to ask the user to accept some terms of service, or ask him to provide an email address/phone number/ID number for verification, etc., before creating the user account.
As far as I know, the only way to interrupt this automatic registration is to modify the SOCIAL_AUTH_PIPELINE of python-social-auth, and provide a partial pipeline function, as mentioned in https://python-social-auth.readthedocs.io/en/latest/pipeline.html#partial-pipeline. However, if you try to implement any partial pipeline function that interrupts the authentication pipeline, the error that I mentioned last time happens.
First of all you don't need to handle anything regarding the python-social-auth library. drf-social-oauth2 will handle this for you.
Without touching the API from python-social-auth library, how to implement the same functionality of interrupting the authentication pipeline in drf-social-oauth2? Thanks!
@exgphe hope you're doing well. I managed to investigate the issue a little further.
I replicated the issue described at: "Same issue as https://github.com/RealmTeam/django-rest-framework-social-oauth2/issues/208"
Here is the pipeline:
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'facebook_setup.pipeline.require_email', # custom pipeline
#'accounts.pipeline.create_custom_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)
From the oauth2_grants, once the backend.do_auth executes, it will move to the custom pipeline and start the redirect (custom pipeline is below)
The pipeline written in the other issue was this:
from social_core.pipeline.partial import partial
@partial
def require_email(strategy, details, user=None, is_new=False, *args, **kwargs):
print("*** In Piepline ***")
# This is for testing purpose that's why no conditions
# I just wanted to know if it can redirect or not
current_partial = kwargs.get('current_partial')
return strategy.redirect('/api/v1/account/email?partial_token={0}'.format(current_partial.token))
However, this piepeline returns a strategy redirection, instead, it should return the username (or a dict wirh a username and other objects)
As you can see from the image above, the user needs should be returned with an attributed is_active
but it doesn't, because the user returned is an HttpResponseRedirect.
If you return the user in the require_email
function, you will have this instead:
This time, the variable user is of time User and it will pass the if condition that was failing before. So I don't think this is at all a problem with drf-social-oauth2 but just a pipeline setting.
Let me know if this was clear enough.
Thank you so much for the response! I encountered this problem in a project two years ago but I’m not involved in it anymore. I’ll ask the current team to see if they still concern about the issue.