与drf进行社交身份验证并做出反应

时间:2019-12-05 10:25:21

标签: django python-3.x django-rest-framework

我正在使用rest_framework_social_auth2库进行社交身份验证,并使用simple-jwt进行身份验证

urls.py:

path('auth/', include('rest_framework_social_oauth2.urls')),

settings.py:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'image',
'crispy_forms',
'django_countries',
'users',
'corsheaders',    
'api',
'sorl.thumbnail',
'rest_framework',
'social_django',  
'rest_social_auth',
'django_filters',
'oauth2_provider', 
'rest_framework_social_oauth2', 
]

REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES':[
    'rest_framework_simplejwt.authentication.JWTAuthentication',        
   'oauth2_provider.contrib.rest_framework.OAuth2Authentication', 
    'rest_framework_social_oauth2.authentication.SocialAuthentication',  
  ],

AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'social_core.backends.facebook.FacebookOAuth2',
'rest_framework_social_oauth2.backends.DjangoOAuth2',  
'django.contrib.auth.backends.ModelBackend',)

SOCIAL_AUTH_FACEBOOK_SCOPE = ['email']
SOCIAL_AUTH_FACEBOOK_PROFILE_EXTRA_PARAMS = {
'fields': 'id, name, email'
 }

SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
 ]

还更改了中间件模板

从Django后端创建了新的应用程序:

enter image description here

这是邮递员的输出:

enter image description here

但是如何为Facebook,google创建api端点。

0 个答案:

没有答案
相关问题