0

我正在尝试使用 Django Social Auth 实现 Twitter 登录。我添加了一个部分管道,我使用表单(DOB、电子邮件等)从用户那里收集额外的详细信息。

我的问题是,如果用户已经存在,我想跳过这个管道。但是,当我尝试这样做时,我得到一个 AuthTokenError“令牌错误:缺少未经授权的令牌”,我无法弄清楚原因。

这是导致问题的代码:

def gather_extra_data(backend, details, uid, request, user=None, *args, **kwargs):
    social_user = UserSocialAuth.get_social_auth(backend.name, uid)

    if social_user:
        return redirect('socialauth_complete', backend.name)

    if not details.get('email'):
        if not request.session.get('saved_email'):
            return redirect(request_extra, backend=backend.name)
        else:
            details['email'] = request.session['saved_email']
            details['password'] = request.session['password']
            details['first_name'] = request.session['first_name']
            details['last_name'] = request.session['last_name']
            details['dob'] = request.session['dob']
            details['gender'] = request.session['gender']
            details['avatar_url'] = request.session['avatar_url']
4

2 回答 2

1

您应该在创建用户并关联社交帐户之后(在social_auth.backends.pipeline.social.associate_user条目之后)放置您的管道条目,然后您可以尝试使用以下代码:

def gather_extra_data(social_auth, user, details, request, is_new=False, *args, **kwargs):
    if is_new:
        if request.session.get('saved_email') is None:
            return redirect(request_extra, backend=backend.name)
        else:
            details['email'] = request.session['saved_email']
            details['password'] = request.session['password']
            details['first_name'] = request.session['first_name']
            details['last_name'] = request.session['last_name']
            details['dob'] = request.session['dob']
            details['gender'] = request.session['gender']
            details['avatar_url'] = request.session['avatar_url']

记得social_auth.backends.pipeline.misc.save_status_to_session在进入之前放。

于 2013-06-16T17:23:10.507 回答
0

试试这个方法:

def gather_extra_data(backend, details, uid, request, user=None, is_new=False, *args, **kwargs):

If not user is None and is_new: #is_new is your missing argument.
    if not details.get('email'):
        if not request.session.get('saved_email'):
            return redirect(request_extra, backend=backend.name)
        else:
            details['email'] = request.session['saved_email']
            details['password'] = request.session['password']
            details['first_name'] = request.session['first_name']
            details['last_name'] = request.session['last_name']
            details['dob'] = request.session['dob']
            details['gender'] = request.session['gender']
            details['avatar_url'] = request.session['avatar_url']
于 2013-06-16T09:07:19.000 回答