我知道为时已晚,但这可能会帮助那些在社交登录方面苦苦挣扎的人,因此将其发布在这里。使用这个模块django-rest-framework-social-oauth2,按照官方 Github 上的说明进行操作,他们有 Facebook 和 Google 的示例。
此外,将这些管道添加到您的设置中
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.auth_allowed',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'social_core.pipeline.social_auth.associate_by_email',
'social_core.pipeline.user.create_user',
'social_core.pipeline.social_auth.associate_user',
'social_core.pipeline.social_auth.load_extra_data',
'social_core.pipeline.user.user_details',
)
这将允许用户使用单个用户帐户的多个社交登录来验证自己的身份。
跑
python manage.py makemigrations
和
python manage.py migrate
如果您已正确按照他们的官方 GitHub 上的说明进行操作,那么您应该能够访问 localhost:8000/auth/convert-token 从那里您可以将您的令牌转换为您的应用程序令牌并使用它来验证用户身份。