gpt4 book ai didi

Python Social Auth 多范围额外数据

转载 作者:太空狗 更新时间:2023-10-30 01:38:06 25 4
gpt4 key购买 nike

我正在为我们的应用程序使用 Python Social Auth,我最近创建了一个双范围 Google 登录。我们的想法是允许用户使用谷歌登录,然后扩大范围以允许我们阅读他们的电子邮件并通过它们解析相关内容。我遵循了文档中概述的建议:http://psa.matiasaguirre.net/docs/use_cases.html#multiple-scopes-per-provider并创建了一个新的后端:

from social.backends.google import GoogleOAuth2
class GoogleEmailOAuth2(GoogleOAuth2):
name = 'google-email'

然后将必要的部分添加到我们的 settings.py(以及所有必要的 url):

SOCIAL_AUTH_GOOGLE_EMAIL_SCOPE = ['email', 'profile', 'https://www.googleapis.com/auth/plus.profile.emails.read']
SOCIAL_AUTH_GOOGLE_EMAIL_AUTH_EXTRA_ARGUMENTS = {'access_type': 'offline'}
SOCIAL_AUTH_GOOGLE_EMAIL_EXTRA_DATA = [
('id', 'user_id'),
('email', 'user_email'),
('refresh_token', 'refresh_token', True),
('expires_in', 'expires'),
('token_type', 'token_type', True)
]

除了创建的 UserSocialAuth 对象在 extra_data 中不包含任何内容外,一切似乎都正常工作……我对普通的 SOCIAL_AUTH_GOOGLE_OAUTH2_EXTRA_DATA 使用了相同的范围,它工作得很好,但对于自定义后端来说仍然是 nada。非常感谢您提出任何建议。

编辑:尝试了几种不同的方法,但仍然无法设置数据。

最佳答案

我没有遇到同样的问题,所以无法回答这个问题,但一个建议是在 load_extra_data 管道函数中放置一个调试断点,然后从那里开始:

def load_extra_data(backend, details, response, uid, user, *args, **kwargs):
#
# <-- Add your debugger of choice, e.g.
# import pdb; pdb.set_trace()
#
social = kwargs.get('social') or \
backend.strategy.storage.user.get_social_auth(backend.name, uid)
if social:
extra_data = backend.extra_data(user, uid, response, details,
*args, **kwargs)
social.set_extra_data(extra_data)

https://github.com/omab/python-social-auth/blob/v0.2.13/social/pipeline/social_auth.py#L82-L88

关于Python Social Auth 多范围额外数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25554896/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com