在社交登录期间使用 django-allauth 传递动态参数 [英] Passing a dynamic state parameter using django-allauth during social login

查看:22
本文介绍了在社交登录期间使用 django-allauth 传递动态参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用 django-allauth 通过社交身份验证传递数据(以便我可以在登录完成后访问它),但我不确定如何执行此操作,因为文档似乎完全缺乏这个区域.

I need to pass data through a social authentication (so I can access it after the login is complete) using django-allauth, but I'm not sure how to go about doing this as the documentation seems to be completely lacking in this area.

据我所知,OAuth2 接受一个状态参数,可用于传输这种数据.在花了几个小时浏览 django-allauth 代码之后,似乎有一些能力附加 动态状态参数.但是,我不知道将这些数据引入请求的正确方法是什么,也不知道应该在什么时候发生.我需要在 socialaccounts/views.py 中修补一些东西吗?不幸的是,socialaccountsadapter.py 似乎没有任何方法可以挂接到这样的请求.

From what I gather, OAuth2 accepts a state parameter that can be used to transfer this sort of data. After spending hours trolling through the django-allauth code, it appears that there might be some ability to append a dynamic state parameter. However, I have no idea what the proper way to introduce this data into the request is, nor at what point this should occur. Do I need to monkey patch something in socialaccounts/views.py? Unfortunately it doesn't seems like the socialaccounts adapter.py has any way to hook into a request like this.

看起来还有一些机会访问状态参数 此处,但同样,我不确定执行此操作的最佳方法.

It looks like there's also some opportunity to access the state parameter here, but again, I'm unsure of the best way to do this.

推荐答案

事实证明,状态参数是一个红鲱鱼;但是,django-allauth 通过 OAuth 请求传递 Django 会话 ID.这允许您在身份验证发生之前将数据安全地存储在 request.session 中,然后在身份验证完成后再次访问它.

It turns out the state parameters were a red herring; however, django-allauth passes the Django session ID through OAuth requests. This allows you to store data safely in request.session before the authentication occurs, and then access it again later after authentication is complete.

这篇关于在社交登录期间使用 django-allauth 传递动态参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆