RealmTeam / django-rest-framework-social-oauth2

python-social-auth and oauth2 support for django-rest-framework
MIT License
1.06k stars 191 forks source link

Pausing Pipeline gives 'HttpResponseRedirect' object has no attribute 'is_active' #208

Open jd-solanki opened 4 years ago

jd-solanki commented 4 years ago

I am using VueJS as my frontend. When I login as facebook and it don't give me email I want to display page from which user can enter email and after that pipeline will continue which will create user with that email.

However in my custom pipeline partial when I return something like below:

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))

It always gives me: 'HttpResponseRedirect' object has no attribute 'is_active' Full traceback: Image

Even if I provide wrong URL in redirect it gets the same error.

Here's my view:

@api_view(['GET', 'POST'])
@permission_classes([AllowAny])
def redirect_login(request, **kwargs):
    # Yes, this needs to return some response but i can not even get to this view
    print("in redict_login view")
    print("kwargs")
    print(kwargs)

This is my 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',
    'accounts.pipeline.require_email',
    'social_core.pipeline.user.get_username',
    'accounts.pipeline.create_custom_user',
    # 'social_core.pipeline.user.create_user',
    'accounts.pipeline.set_custom_data',
    'social_core.pipeline.social_auth.associate_user',
    'social_core.pipeline.social_auth.load_extra_data',
    'social_core.pipeline.user.user_details',
)

Here's my settings:
```python
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        # 'oauth2_provider.ext.rest_framework.OAuth2Authentication',  # django-oauth-toolkit < 1.0.0
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',  # django-oauth-toolkit >= 1.0.0
        'rest_framework_social_oauth2.authentication.SocialAuthentication',
    ),
}

AUTHENTICATION_BACKENDS = (
   'social_core.backends.facebook.FacebookOAuth2',
   'rest_framework_social_oauth2.backends.DjangoOAuth2',
   'django.contrib.auth.backends.ModelBackend',
)

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # 3rd Party
    'rest_framework', # API
    'corsheaders', # CORS

    # Social Logins
    'oauth2_provider',
    'social_django',
    'rest_framework_social_oauth2',

    # Local
    'accounts', # Handles user/account mgmt
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'corsheaders.middleware.CorsMiddleware', # CORS
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

CORS_ORIGIN_ALLOW_ALL = True

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]

SOCIAL_AUTH_FACEBOOK_KEY = 'MY_KEY'
SOCIAL_AUTH_FACEBOOK_SECRET = 'SECRET'

Do i need anything else to setup in settings.py? Whats: DRFSO2_PROPRIETARY_BACKEND_NAME & DRFSO2_URL_NAMESPACE

Here's my stackoverflow question.

wagnerdelima commented 4 years ago

Hi all.

My team and I are constantly using this framework and it seems it has died out there. I contacted the owner by email asking if he would add some of us as maintainers so we could continue to improve it. However we didn't get a response.

I am publishing the project under my profile and we are going to continue to invest time in it.

So I would like to gently ask you to contribute to this project on: https://github.com/wagnerdelima/drf-social-oauth2

Thank you for understanding.

wagnerdelima commented 1 year ago

@jd-solanki read https://github.com/wagnerdelima/drf-social-oauth2/issues/21. Let me know if it answers your questions. Thanks.

jd-solanki commented 1 year ago

Hi @wagnerdelima

Thanks for your response. Unfortunetly, That project is abandoned. Feel free to close this because I won't be able to test it 😓

Thanks for your response 🙏🏻