更新时间:2022-06-18 14:58:36
我还集成了djangorest framework+django-allauth+django-睡觉-auth+djangorest framework-jwt。 但是,我只是在Google上实现了登录,所以用户不能手动注册。
以下是我的代码:
views.py
from allauth.socialaccount.providers.google.views import GoogleOAuth2Adapter
from allauth.socialaccount.providers.oauth2.client import OAuth2Client
from rest_auth.registration.views import SocialLoginView
class GoogleLogin(SocialLoginView):
adapter_class = GoogleOAuth2Adapter
client_class = OAuth2Client
urls.py
...
path('auth/google', GoogleLogin.as_view(), name='google_login'),
...
settings.py
INSTALLED_APPS = [
...
'allauth',
'allauth.account',
'allauth.socialaccount',
'allauth.socialaccount.providers.google',
...
]
SITE_ID = 1
REST_USE_JWT = True # this is for djangorestframework-jwt
[更新]
要在SocialLoginView终结点上使用code
params:
https://accounts.google.com/o/oauth2/v2/auth?redirect_uri=<https_callback>&prompt=consent&response_type=code&client_id=<cliend_id>&scope=email&access_type=offline
这篇关于谷歌登录姜戈睡觉框架+allauth+睡觉-auth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!