【问题标题】:Django + Python social auth: How to configure OAuth for GitHub Enterprise?Django + Python 社交身份验证:如何为 GitHub Enterprise 配置 OAuth?
【发布时间】:2020-05-27 17:58:43
【问题描述】:

使用 Django 和 social-auth-app-django,我可以使用 https://github.comsocial_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。让我检查一下!

标签: django github oauth-2.0


【解决方案1】:

"{% url 'social:begin' 'github' %}" 应该是"{% url 'social:begin' 'github-enterprise' %}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-20
    • 1970-01-01
    • 1970-01-01
    • 2014-04-18
    • 1970-01-01
    相关资源
    最近更新 更多