【发布时间】:2018-06-10 03:04:51
【问题描述】:
我正在使用的应用程序有一个 Python Social Auth /complete/<backend>/ 端点的覆盖端点。
在我们的urls.py:
urlspatterns = [
...
# Override of social_auth
url(r'^api/v1/auth/oauth/complete/(?P<backend>[^/]+)/$',
social_auth_complete,
name='social_complete'),
...
]
views.py内:
from social_django.views import complete
def social_auth_complete(request, backend, *args, **kwargs):
"""Overwritten social_auth_complete."""
# some custom logic getting variables from session (Unrelated).
response = complete(request, backend, *args, **kwargs)
# Some custom logic adding args to the redirect (Unrelated).
我们正在尝试实现partial pipeline method。第一次调用端点时,一切都按预期工作。
@partial
def required_info(strategy, details, user=None, is_new=False, *args, **kwargs):
"""Verify the user has all the required information before proceeding."""
if not is_new:
return
for field in settings.SOCIAL_USER_REQUIRED_DATA:
if not details.get(field):
data = strategy.request_data().get(field)
if not data:
current_partial = kwargs.get('current_partial')
social_provider = kwargs.get('backend')
return strategy.redirect(f'.../?partial_token={partial_token}&provider={social_provider}'
else:
details[field] = data
这会将用户重定向到前端,他们在其中填写一个表单,该表单调用 POST 请求到原始 API api/v1/auth/oauth/complete/(?P<backend>[^/]+)/,数据中包含以下内容:
{
'required_fieldX': '数据',
...
'partial_token': '',
}
关键问题
有两个问题;当我 pdb 进入required_info 时,strategy.request_data() 中永远不会有任何数据。 kwargs['request'].body 里面还有数据,我可以把数据拿出来。
然而
但我担心第二次我们永远不会从 social-core 进入这个block of code:
partial = partial_pipeline_data(backend, user, *args, **kwargs)
if partial:
user = backend.continue_pipeline(partial)
# clean partial data after usage
backend.strategy.clean_partial_pipeline(partial.token)
else:
user = backend.complete(user=user, *args, **kwargs)
我知道这是真的,因为当我查询数据库时,原始 Partial 对象仍然存在,就好像从未调用过 backend.strategy.clean_partial_pipeline(partial.token)。
最后的问题
为什么social_django.views.complete 没有按预期处理 POST 请求,并且在所有示例应用程序中似乎都如此。我们覆盖它有问题吗?我是否应该只创建一个单独的端点来处理 POST 请求,如果是这样,如何模仿@psa 中发生的所有事情,以便我可以调用backend.continue_pipeline(partial)?
【问题讨论】:
-
可以This be the problem 这个工作的所有示例都显示表单提交,但我正在做
application/json提交。 This is the key piece of code I need to work