django-social-auth不正确的身份验证服务

Uri*_*che 5 django facebook oauth socialauth

我今天尝试使用django-social-auth,但事实证明我每次尝试使用它时都会出错.

我正在使用在其git master分支中找到的示例,放入我的facebook密钥,但是当我点击使用facebook登录时,出现错误"不正确的身份验证服务".

这也发生在twitter和orkut登录中......有没有人知道为什么会发生这种情况?

非常感谢!

编辑

是的,对不起,我忘记发布我的代码了.

settings.py

from os.path import abspath, dirname, basename, join

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ROOT_PATH = abspath(dirname(__file__))
PROJECT_NAME = basename(ROOT_PATH)

ADMINS = (
    # ('Your Name', 'your_email@domain.com'),
)
MANAGERS = ADMINS

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'test.db',
    }
}

TIME_ZONE = 'America/Chicago'
LANGUAGE_CODE = 'en-us'
SITE_ID = 1

USE_I18N = True
USE_L10N = True

MEDIA_ROOT = ''
ADMIN_MEDIA_PREFIX = '/admin-media/'
MEDIA_URL = ''

SECRET_KEY = '****'

TEMPLATE_LOADERS = (
    'django.template.loaders.filesystem.Loader',
    'django.template.loaders.app_directories.Loader',
)

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'urls'

TEMPLATE_DIRS = (
    join(ROOT_PATH, 'templates')
)

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.admin',
    'social_auth',
    'app',
)

AUTHENTICATION_BACKENDS = (
    'social_auth.backends.twitter.TwitterBackend',
    'social_auth.backends.facebook.FacebookBackend',
    'social_auth.backends.google.GoogleOAuthBackend',
    'social_auth.backends.google.GoogleOAuth2Backend',
    'social_auth.backends.google.GoogleBackend',
    'social_auth.backends.yahoo.YahooBackend',
    'social_auth.backends.contrib.linkedin.LinkedinBackend',
    'social_auth.backends.OpenIDBackend',
    'social_auth.backends.contrib.livejournal.LiveJournalBackend',
    'django.contrib.auth.backends.ModelBackend',
)

try:
    from local_settings import *
except:
    pass
Run Code Online (Sandbox Code Playgroud)

local_settings.py

TWITTER_CONSUMER_KEY              = ''
TWITTER_CONSUMER_SECRET           = ''
FACEBOOK_APP_ID                   = '226521154024720'
FACEBOOK_API_SECRET               = '9955be3b6e211b51921cb4b8eb08e69e'
LINKEDIN_CONSUMER_KEY             = ''
LINKEDIN_CONSUMER_SECRET          = ''
ORKUT_CONSUMER_KEY                = ''
ORKUT_CONSUMER_SECRET             = ''
GOOGLE_OAUTH2_CLIENT_KEY          = ''
GOOGLE_OAUTH2_CLIENT_SECRET       = ''
SOCIAL_AUTH_CREATE_USERS          = True
SOCIAL_AUTH_FORCE_RANDOM_USERNAME = False
SOCIAL_AUTH_DEFAULT_USERNAME      = 'socialauth_user'
SOCIAL_AUTH_COMPLETE_URL_NAME     = 'complete'
LOGIN_ERROR_URL                   = '/login/error/'
#SOCIAL_AUTH_USER_MODEL            = 'app.CustomUser'
SOCIAL_AUTH_ERROR_KEY             = 'socialauth_error'
Run Code Online (Sandbox Code Playgroud)

如果您需要任何其他代码,其余代码在github.com/omab/django-social-auth中的示例完全相同,请告诉我.

非常感谢!

ady*_*ady 11

在我的情况下,问题是我有FACEBOOK_APP_SECRET而不是FACEBOOK_API_SECRET.这是因为我从django-facebook迁移到了django-social-auth.


Loc*_*jaw 1

好吧,如果没有看到您的配置,这将只是瞎猜。但django-social-auth代码中有这样的:

def complete_process(request, backend):
    """Authentication complete process"""
    backend = get_backend(backend, request, request.path)
    if not backend:
        return HttpResponseServerError('Incorrect authentication service')
    ...
Run Code Online (Sandbox Code Playgroud)

所以,我猜你没有配置正确的后端,或者至少 Django 找不到它。确保您配置了适当的后端AUTHENTICATION_BACKENDS,并且您已从要使用的服务获取了所需的 OAuth 密钥。

还要记住,此错误会在django-social-auth代码中的几个地方发生,但总是在无法检索指定的后端时发生。

  • 我不认为你有诵读困难——我认为当你盯着代码一段时间时,类似这样简单的事情总是会发生。有时,拥有另一双眼睛就会有所帮助!快乐编码。 (3认同)