django-social-auth 认证服务不正确

发布于 2024-11-13 05:48:45 字数 3247 浏览 2 评论 0原文

我今天尝试使用 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', '[email protected]'),
)
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

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'

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

多谢!

I was trying to use django-social-auth today, but turned out I got an error everytime I tried to login using it.

I was using the example found in its git master branch, put in my facebook keys, but when I click to login using facebook, the error "Incorrect authentication service" appears.

That also occurs in twitter and orkut logins... does anyone have any idea why that may be happening?

Thanks a lot!

Edit

Yeah, I'm sorry, I forgot to post my code.

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', '[email protected]'),
)
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

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'

The rest of the codes are exactly the same in example in github.com/omab/django-social-auth
if you need any other code, just tell me.

Thanks a lot!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

楠木可依 2024-11-20 05:48:45

就我而言,问题是我有 FACEBOOK_APP_SECRET 而不是 FACEBOOK_API_SECRET。这是因为我从 django-facebook 迁移到 django-social-auth。

In my case the problem was that I had FACEBOOK_APP_SECRET instead of FACEBOOK_API_SECRET. It was due to the fact that I migrated from django-facebook to django-social-auth.

眼泪也成诗 2024-11-20 05:48:45

可能是您没有设置 FACEBOOK_APP_ID 或 FACEBOOK_API_SECRET。

It may be you don't have the FACEBOOK_APP_ID or FACEBOOK_API_SECRET set.

晨光如昨 2024-11-20 05:48:45

好吧,如果没有看到您的配置,这将只是瞎猜。但是 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')
    ...

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

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

Well, without seeing your configuration this will simply be a shot in the dark. But the django-social-auth code has this:

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

So, offhand, I would guess that you don't have the right backend configured or, at the very least, Django can't find it. Make sure you have the appropriate backend configured in AUTHENTICATION_BACKENDS and that you've obtained the required OAuth keys from the service you want to use.

Keep in mind, too, that this error occurs in the django-social-auth code in a few places, but always when the specified backend can't be retrieved.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文