[英]Django request.user become AnonymousUser after third party redirect
test.html: 的test.html:
<a href="https://auth.ebay.com/oauth2/authorize? ...">authorize</a>
views.py: views.py:
from django.contrib.auth.decorators import login_required
@login_required
def myview(req):
user = req.user
return render(req, 'test.html')
For ebay's oauth process, you have to provide users with a link to ebay's server, which asks the user if they want to give credentials to you. 对于ebay的oauth流程,您必须向用户提供指向ebay服务器的链接,该服务器会询问用户是否要向您提供凭据。 If they accept, ebay redirects the user to a given url with a querystring containing the access key. 如果他们接受,ebay会将用户重定向到包含访问密钥的查询字符串的给定网址。
The problem is, when I authorize my app with ebay, the user gets redirected to my login page (despite already being logged in). 问题是,当我用ebay授权我的应用程序时,用户会被重定向到我的登录页面(尽管已经登录)。 If I remove the @login_required
decorator, req.user
returns AnonymousUser instead. 如果我删除@login_required
装饰器, req.user
将返回AnonymousUser。 This is a problem since I don't know which user to assign the access token to. 这是一个问题,因为我不知道将访问令牌分配给哪个用户。
What am I missing here? 我在这里错过了什么?
Note that I am using ngrok to tunnel my server, and I have no problems 请注意 ,我使用ngrok隧道服务器,我没有问题
rendering myview
other than the fact that the user is Anonymous. 除了用户是匿名的事实之外,渲染myview
。
The problem was that when I logged the user in initially, I was using the domain localhost:8000
instead of my ngrok instance. 问题是,当我最初登录用户时,我使用域localhost:8000
而不是我的ngrok实例。
Logging my user in using my ngrok address fixed the problem. 使用我的ngrok地址记录我的用户修复了问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.