【发布时间】:2020-05-27 17:58:43
【问题描述】:
使用 Django 和 social-auth-app-django,我可以使用 https://github.com 和 social_core.backends.github.GithubOAuth2 后端进行授权。
我正在尝试根据此文档将其切换到我们的 GitHub Enterprise; https://python-social-auth.readthedocs.io/en/latest/backends/github_enterprise.html#github-enterprise
这是我的settings.py:
INSTALLED_APPS = [
...
'social_django',
]
MIDDLEWARE = [
...
'social_django.middleware.SocialAuthExceptionMiddleware',
]
TEMPLATES = [
{
...
'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',
...
]
SOCIAL_AUTH_GITHUB_ENTERPRISE_URL = 'https://github.mycompany.com/'
SOCIAL_AUTH_GITHUB_ENTERPRISE_API_URL = 'https://github.mycompany.com/api/v3/'
SOCIAL_AUTH_GITHUB_ENTERPRISE_KEY = '----'
SOCIAL_AUTH_GITHUB_ENTERPRISE_SECRET = '----'
AUTHENTICATION_BACKENDS = (
'social_core.backends.github_enterprise.GithubEnterpriseOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
但它抱怨以下错误:
Page not found (404)
Request Method: GET
Request URL: http://127.0.0.1:8000/social-auth/login/github/
Raised by: social_django.views.auth
Backend not found
我确定social_core.backends.github_enterprise.GithubEnterpriseOAuth2 的班级在/usr/local/lib/python3.8/site-packages/social_core/backends/github_enterprise.py 中。
如果我将后端用作social_core.backends.github.GithubOAuth2,它会重定向到不想要的https://github.com/login/oauth/authorize?。
能否指导我如何为 GitHub Enterprise 设置后端?
【问题讨论】:
-
哦,我错过了将 "{% url 'social:begin' 'github' %}" 更改为 github-enterprise。让我检查一下!