Skip to main content
 首页 » 编程设计

python之不验证用户 django-social-auth

2024年10月17日29lovecherry

用户点击链接/login/steam。之后一切正常(django.contrib.auth 用户实例和 social_auth 用户实例创建良好,自定义管道工作。但是当我尝试使用 request.user 在我的 View 中使用 steam 登录后我有错误

'AnonymousUser' object is not iterable

我的settings.py文件

SOCIAL_AUTH_PIPELINE = ( 
'social.pipeline.social_auth.social_details', 
'social.pipeline.social_auth.social_uid', 
'social.pipeline.social_auth.social_user', 
# custom pipeline 
'markers.pipeline.add_steam_data_marker', 
#  
'social.pipeline.user.get_username', 
'social.pipeline.user.create_user', 
'social.pipeline.social_auth.auth_allowed', 
'social.pipeline.social_auth.associate_user', 
'social.pipeline.social_auth.load_extra_data', 
'social.pipeline.user.user_details', ) 

我在应用程序中的自定义 pipeline.py

def add_steam_data_marker(strategy, details, backend, uid, *args, **kwargs): 
 
if backend.name == 'steam': 
    try: 
        Model.objects.get(steam_user_id=uid) 
        return redirect('/home/') 
    except ObjectDoesNotExist: 
       Model.objects.create( 
            ........, 
        ) 
 
       return redirect('/model/add/') 

请您参考如下方法:

所有的麻烦都在 AUTHENTICATION_BACKENDS 不要用户社交。 ..... 使用 social_core ->'social_core.backends.steam.SteamOpenId',