omab / django-social-auth

Django social authentication made simple
https://groups.google.com/group/django-social-auth
BSD 3-Clause "New" or "Revised" License
2.65k stars 756 forks source link

Facebook: Authentication process canceled #851

Closed 4doge closed 7 years ago

4doge commented 7 years ago

Hi all,

I need to add rest auth from Facebook and Google Plus to my project. I found that module and think that it easy to use and integrate, but i have some troubles with that. An error - "AuthCanceled at /complete/facebook/ Authentication process canceled" My settings.py:

SOCIAL_AUTH_USER_MODEL = 'accounts.User'
AUTHENTICATION_BACKENDS = (
    'social_core.backends.open_id.OpenIdAuth',
    'social_core.backends.google.GoogleOpenId',
    'social_core.backends.google.GoogleOAuth2',
    'social_core.backends.google.GoogleOAuth',
    'social_core.backends.twitter.TwitterOAuth',
    'social_core.backends.yahoo.YahooOpenId',
    'social_core.backends.facebook.FacebookOAuth2',
    'social_core.backends.facebook.FacebookAppOAuth2',
)
SOCIAL_AUTH_FACEBOOK_KEY = "MY_KEY_HERE"
SOCIAL_AUTH_FACEBOOK_SECRET = "MY_SECRET_HERE"
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',
            ],
        },
    },
]
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',
    'social_django.middleware.SocialAuthExceptionMiddleware',
]
INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',

    # Django apps
    'accounts',
    'games',
    'core',

    # 3rd-party apps
    'rest_framework',
    'rest_framework.authtoken',
    'rest_framework_docs',
    'solo',
    'redactor',
    'corsheaders',
    'social_django',
]

I have add localhost to my Facebook app. So i go to localhost:8000/login/facebook/ allow to get info from my account and redirect to localhost:8000/complete/facebook/ with AuthCanceled error. So what's the error? And what workflow needs to be if i have AngularJS on the front-end and REST API via Django / Django REST Framework.

Many thanks, Anton