wagnerdelima / drf-social-oauth2

drf-social-oauth2 makes it easy to integrate Django social authentication with major OAuth2 providers, i.e., Facebook, Twitter, Google, etc.
https://drf-social-oauth2.readthedocs.io/en/latest/
MIT License
274 stars 34 forks source link

convert-token return access_denied in facebook backend #185

Open yunica opened 1 year ago

yunica commented 1 year ago

I went through the process in the guide and when I try keys it gives me an error.

{"error":"access_denied","error_description":"Authentication process canceled"}

I've researched in the documentation but can't find a clear answer. Could there be an internal error?

image

wagnerdelima commented 1 year ago

You need to include more details about your configuration and also the exception stacktrace.

yunica commented 1 year ago

I have some details, I did the normal configuration, change the host and create an application in the admin. I can't find documentation about this error.

settings.py


DJANGO_APPS = [
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.forms",
]

THIRD_PARTY_APPS = [
    "rest_framework",

    "captcha",
    "debug_toolbar",

    "oauth2_provider",
    "social_django",
    "drf_social_oauth2",
]

LOCAL_APPS = [
    "base.apps.BaseConfig",
]

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + LOCAL_APPS

TEMPLATES = [
    {
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [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",
                # context auth
                "social_django.context_processors.backends",
                "social_django.context_processors.login_redirect",
                # custom context
            ],
        },
    },
]

REST_FRAMEWORK = {
    "DEFAULT_PERMISSION_CLASSES": (),
    "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
        "drf_social_oauth2.authentication.SocialAuthentication",
    ),
}

AUTHENTICATION_BACKENDS = (

    # Facebook OAuth2
    "social_core.backends.facebook.FacebookAppOAuth2",
    "social_core.backends.facebook.FacebookOAuth2",
    # drf_social_oauth2
    "drf_social_oauth2.backends.DjangoOAuth2",
    # Django
    "django.contrib.auth.backends.ModelBackend",
)
# Facebook configuration
SOCIAL_AUTH_FACEBOOK_KEY = "13xxxxxxxx"
SOCIAL_AUTH_FACEBOOK_SECRET = "e5exxxxxxxxxxxxxxxxxxxxxx"
SOCIAL_AUTH_FACEBOOK_SCOPE = ["email"]
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {"fields": "id, name, email"}

facebook app

image

requirements.txt

asgiref==3.7.2
beautifulsoup4==4.12.2
certifi==2023.5.7
cffi==1.15.1
charset-normalizer==3.1.0
cryptography==41.0.1
defusedxml==0.7.1
Deprecated==1.2.14
Django==4.2.1
django-appconf==1.0.5
django-compressor==4.3.1
django-debug-toolbar==4.1.0
django-dotenv==1.4.2
django-htmlmin==0.11.0
django-naomi==0.8
django-oauth-toolkit==2.3.0
django-querycount==0.8.3
django-ranged-response==0.2.0
django-simple-captcha==0.5.17
djangorestframework==3.14.0
drf-social-oauth2==2.1.2
ecdsa==0.18.0
html5lib==1.1
idna==3.4
jwcrypto==1.5.0
oauthlib==3.2.2
Pillow==9.5.0
psycopg2-binary==2.9.6
pyasn1==0.5.0
pycparser==2.21
PyJWT==2.7.0
python-jose==3.3.0
python3-openid==3.2.0
pytz==2023.3
rcssmin==1.1.1
requests==2.31.0
requests-oauthlib==1.3.1
rjsmin==1.2.1
rsa==4.9
six==1.16.0
social-auth-app-django==5.2.0
social-auth-core==4.4.2
soupsieve==2.4.1
sqlparse==0.4.4
typing_extensions==4.6.2
urllib3==1.26.16
webencodings==0.5.1
wrapt==1.15.0

host

127.0.0.1   dev.myapp.com

exception

WARNING 01/Jun/2023 12:51:01 log.py log:log_response:241  Bad Request: /auth/convert-token
WARNING 01/Jun/2023 12:51:01 basehttp.py basehttp:log_message:212  "POST /auth/convert-token HTTP/1.1" 400 79
cloudlessdreams commented 8 months ago

hey @wagnerdelima did figure out how to solve this?