drf-social-oauth2 icon indicating copy to clipboard operation
drf-social-oauth2 copied to clipboard

Invalid backend when converting token on server

Open crozarakamilla opened this issue 3 years ago • 6 comments

Hey there! First of all thank you for keeping this project alive.

I've been struggling a little bit to get things working on the server. When running locally it works like a charm:

image

But when I try to do the same on the server (over https) I'm getting the Invalid backend parameter error:

image

It's the same error if I try with facebook or google-oauth2 backends.

Here are the configs:

DEBUG = False

CORS_ORIGIN_ALLOW_ALL = DEBUG

CORS_ALLOWED_ORIGINS = ['http://localhost:4201', 'http://localhost:8000',
                        'https://desenv.valuemachine.com.br', 'https://valuemachine.com.br']

ALLOWED_HOSTS = ['localhost',
                 'desenv.valuemachine.com.br', 'valuemachine.com.br']

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
    'rest_framework.authtoken',
    'corsheaders',
    'django_filters',
    'drf_yasg',
    'oauth2_provider',
    'social_django',
    'drf_social_oauth2',
]

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

ROOT_URLCONF = 'mercado_financeiro.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['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',
            ],
        },
    },
]

REST_FRAMEWORK = {
    'PAGE_SIZE': 20,

    'EXCEPTION_HANDLER': 'rest_framework_json_api.exceptions.exception_handler',

    'DEFAULT_PAGINATION_CLASS': 'rest_framework_json_api.pagination.JsonApiPageNumberPagination',
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
        'drf_social_oauth2.authentication.SocialAuthentication',
    ],
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework.permissions.AllowAny',
    ],
    'DEFAULT_PARSER_CLASSES': [
        'rest_framework_json_api.parsers.JSONParser',
        'rest_framework.parsers.FormParser',
        'rest_framework.parsers.MultiPartParser'
    ],
    'DEFAULT_RENDERER_CLASSES': [
        'rest_framework_json_api.renderers.JSONRenderer',
        'rest_framework.renderers.BrowsableAPIRenderer',
    ],
    'DEFAULT_METADATA_CLASS': 'rest_framework_json_api.metadata.JSONAPIMetadata',
    'DEFAULT_FILTER_BACKENDS': [
        'rest_framework_json_api.filters.QueryParameterValidationFilter',
        'rest_framework_json_api.filters.OrderingFilter',
        'rest_framework_json_api.django_filters.DjangoFilterBackend',
        'rest_framework.filters.SearchFilter',
    ],
    'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
    'SEARCH_PARAM': 'filter[search]',
    'ORDERING_PARAM': 'sort',
    'TEST_REQUEST_RENDERER_CLASSES': [
        'rest_framework_json_api.renderers.JSONRenderer',
    ],
    'TEST_REQUEST_DEFAULT_FORMAT': 'vnd.api+json'
}

AUTHENTICATION_BACKENDS = (
    'social_core.backends.facebook.FacebookAppOAuth2',
    'social_core.backends.facebook.FacebookOAuth2',
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.linkedin.LinkedinOAuth2',
    'drf_social_oauth2.backends.DjangoOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

# Facebook configuration
SOCIAL_AUTH_FACEBOOK_KEY = 'xxxx'
SOCIAL_AUTH_FACEBOOK_SECRET = 'xxxx'
SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
    'fields': 'id, name, email'
}

# Google configuration
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = 'xxxx'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = 'xxx'

SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
    'https://www.googleapis.com/auth/userinfo.email',
    'https://www.googleapis.com/auth/userinfo.profile',
]

Have you ever had this issue? Do you have a clue about it? I'm very confused about this because it was supposed to work just fine since it is working when I am running locally.

crozarakamilla avatar May 03 '21 15:05 crozarakamilla

Hi @crozarakamilla. Thank you.

I have seen this error before. I realised it was because I didn't have an Application called facebook in production. Can you cehck that please?

wagnerdelima avatar May 04 '21 10:05 wagnerdelima

Thank your for your answer.

You mean the DJANGO OAUTH TOOLKIT's Application?

I've changed the name, but still the same error:

image

crozarakamilla avatar May 05 '21 00:05 crozarakamilla

Seems a bit exoteric to me. My apps work either locally or for production purposes.

What is that algorithm section No OICD support? I don't have that included. Is this from latest versions of your social python?

What are the versions of your oauth2_provider and social_django you are using?

wagnerdelima avatar May 05 '21 12:05 wagnerdelima

Hey there! Here are the versions I am using on my project:

django-oauth-toolkit==1.5.0 social-auth-app-django==4.0.0 social-auth-core==4.1.0 oauthlib==3.1.0 drf-social-oauth2==1.0.9

It's the first time I am using this package and I just left this OICD support as default.

crozarakamilla avatar May 05 '21 13:05 crozarakamilla

@wagnerdelima Similarly I am resulting the same issue where the settings are all fine but the response return as invalid backend

timothyshen avatar Jun 10 '21 23:06 timothyshen

@crozarakamilla and @timothyshen

Did you manage to overcome this situation?

wagnerdelima avatar Dec 24 '21 14:12 wagnerdelima

@crozarakamilla and @timothyshen did you manage to get it to work?

wagnerdelima avatar Mar 26 '23 15:03 wagnerdelima