【发布时间】:2018-07-18 10:18:46
【问题描述】:
在一个个人项目中,我尝试使用 Django 作为我的前端,然后允许将用户以特定形式输入的数据复制到谷歌表格。
Google 自己的文档建议使用 https://github.com/google/oauth2client,它现在已被弃用,并且文档尚未更新。有了这个,我开始尝试使用Python Social Auth 和Gspread。为了使 Gspread 能够正常运行,我不仅需要能够传递访问令牌,还需要能够传递刷新令牌。然而,Python Social Auth 并没有将刷新令牌与其余的“额外数据”一起保留。查看保存的数据和路由到的 URL,在我看来更像是通过 Google+ 路由的某个地方。
我的 Django 设置文件中有以下配置:
AUTHENTICATION_BACKENDS = (
'social_core.backends.google.GoogleOAuth2',
'django.contrib.auth.backends.ModelBackend',
)
SOCIAL_AUTH_PIPELINE = (
'social_core.pipeline.social_auth.social_details',
'social_core.pipeline.social_auth.social_uid',
'social_core.pipeline.social_auth.social_user',
'social_core.pipeline.user.get_username',
'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',
'social_core.pipeline.social_auth.associate_by_email',
)
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '...'
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '...'
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = ['https://www.googleapis.com/auth/spreadsheets']
- 有没有更好的方法来访问 Google 表格?
- 我是否更正了 PSA 或 google 将我重定向到 Google+ 身份验证流程而不是 Google Oauth2?
- 如果不是,必须进行哪些更改才能使 Python Social Auth 保留刷新令牌?
【问题讨论】:
标签: python django oauth-2.0 google-oauth python-social-auth