2

对于我正在从事的 Django 项目,除了 python social auth 提供的社交身份验证方法之外,我还尝试实现和集成无密码身份验证流程。除了其他优点之外,这种方法对我来说最吸引人的部分是,它统一了注册和登录,就像其他社交身份验证后端一样。这提供了电子邮件身份验证的统一

每次用户想要登录(或注册)时,他们只需提交他们的电子邮件,通过电子邮件接收临时登录令牌,点击它,他们就进入了。一个持久的会话被启动,所以他们不需要做它经常。

如文档中所述,我正在使用自定义 EMAIL_VALIDATION_FUNCTION 发送电子邮件,并且它可以很好地发送令牌。我的管道如下所示:

SOCIAL_AUTH_PIPELINE = (
    'social.pipeline.social_auth.social_details',
    'social.pipeline.social_auth.social_uid',
    'social.pipeline.social_auth.auth_allowed',
    'social.pipeline.social_auth.social_user',
    'social.pipeline.user.get_username',
    'social.pipeline.mail.mail_validation',
    'barrio.profiles.pipeline.authenticate_email',  # custom method to authenticate email
    'social.pipeline.social_auth.associate_by_email',
    'social.pipeline.user.create_user',
    'social.pipeline.social_auth.associate_user',
    'social.pipeline.social_auth.load_extra_data',
    'social.pipeline.user.user_details',
)

单击身份验证链接时(即/complete/email/?validation_code=),管道从“social.pipeline.mail.mail_validation”恢复,并且存在身份验证失败的管道,并且执行永远不会到达我的自定义身份验证功能。

即使这样做了,我也不清楚如何访问验证结果并检查它是否正常。

与其尝试在管道上执行此操作,不如使用自定义视图执行此操作,而不是将用户定向到“/email/complete/”视图,而是将它们定向到我的视图并进行身份验证?

Python 社交身份验证因其灵活性而非常出色,但代价是复杂性。有时我会感到失落。感谢您的帮助。

4

0 回答 0