python - django all-auth 通过 twitch 进行身份验证
问题描述
我正在尝试使用 Django 和 reactjs 从 twitch Auth 验证用户。我能够授权用户并将其详细信息从后端存储在 Django 管理员中,但不知道如何从 reactjs 执行此操作。
到目前为止我尝试了什么:
按照这里的文件:https ://django-allauth.readthedocs.io/en/latest/installation.html
我将所有内容配置为:
设置.py:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'rest_framework.authtoken',
'rest_auth',
'django.contrib.sites',
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.twitch',
'django_extensions',
'users.apps.UsersConfig',
]
SITE_ID = 1
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = app-name.urls'
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',
],
},
},
]
WSGI_APPLICATION = 'sphinx.wsgi.application'
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework.authentication.TokenAuthentication',
],
}
我还在 Django 管理员中注册了社交应用程序。
当我击中:
http://localhost:8000/accounts/twitch/login/
它把我带到了 twitch 授权页面,当我点击“授权”时,Django 管理员中的用户详细信息将我重定向回 url:
http://localhost:8000/accounts/profile/
问题是我需要确保 LOGIN_REDIRECT_URL 页面 '/accounts/profile/' 具有一些身份验证,因此只有登录用户才能访问它并显示该用户的用户名。
如何对用户进行身份验证?比如我如何将 access_token 发送到前端 reactjs 并验证用户?
解决方案
推荐阅读
- ubuntu - 我想在 Ubuntu 上安装 Google Assistant 以在屏幕/用户锁定开启时进行监听
- android - 在 Playstore 上上传新应用 - 导入失败
- c# - 给定元数据信息并从 SQL 语法解析树,如何确定 SQL 语句中的列属于哪个表?
- angular - 如何将信息传递给模态?
- java - 在 IntelliJ IDEA 中部署 RESTful Jersey 服务时,在此上下文中无法修改获取资源配置
- python - 熊猫连接字符串,包括按列分组
- python - python中的字符串搜索 - 两个列表
- python - 是否可以在字典中设置 tkinter 条目的顺序?
- sql - 使用 WHERE AND 子句计算唯一记录?
- python-3.x - 保持 3d 距离的负值