1

我使用https://github.com/python-social-auth/social-app-django 它可以轻松地将新的 oauth 添加到我的 django 应用程序中。

我已将其添加到我的设置文件并填写了密钥。

网址.py

urlpatterns = [
    path('', include('home.urls')),
    path('admin/', admin.site.urls),
    path('auth/', include('social_django.urls', namespace='social')),
]

设置.py

SOCIAL_AUTH_COINBASE_KEY = os.environ.get('COINBASE_ID')
SOCIAL_AUTH_COINBASE_SECRET = os.environ.get('COINBASE_SECRET')

AUTHENTICATION_BACKENDS = (
    'social_core.backends.open_id.OpenIdAuth',  # for Google authentication
    'social_core.backends.google.GoogleOpenId',  # for Google authentication
    'social_core.backends.google.GoogleOAuth2',  # for Google authentication
    'social_core.backends.coinbase.CoinbaseOAuth2',  # for Coinbase authentication
    'django.contrib.auth.backends.ModelBackend',
)

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',  # <- Here
                'social_django.context_processors.login_redirect', # <- Here
            ],
        },
    },
]

INSTALLED_APPS = [
    'user.apps.UserConfig',     
    'django.contrib.humanize',

    'social_django',

    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

但是,当我看到 coinbase 的 oauth 屏幕时,我按下下一步,我被重定向到我的重定向 uri,

然后它给了我一个错误

HTTPError at /auth/complete/coinbase/
403 Client Error: Forbidden for url: https://api.coinbase.com/v2/user

我已经尝试解决这个问题几个小时了,但我似乎找不到任何关于这个的东西

4

0 回答 0