简体   繁体   English

Django request.user在第三方重定向后成为AnonymousUser

[英]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.

相关问题 登录门户后,在我的 Django 门户中,我的 request.user 始终提供值 AnonymousUser - In my Django portal after login to the portal my request.user is always giving the value AnonymousUser Django oauth2 request.user返回AnonymousUser - Django oauth2 request.user returns AnonymousUser 无法使用django rest框架进行身份验证(request.user = AnonymousUser) - Not able to authenticate using the django rest framework (request.user = AnonymousUser) Django request.user在重定向后变为匿名 - Django request.user becomes anonymous after redirect AbstractUser 上的 request.user 给出 AnonymousUser TypeError - request.user on AbstractUser gives AnonymousUser TypeError 第一个 django rest api 调用返回 request.user 作为 AnonymousUser 但进一步调用返回正确的用户 - First django rest api call returns request.user as AnonymousUser but further calls return proper user 用户在Django中的哪个位置成为AnonymousUser? - Where in Django does a user become an AnonymousUser? Allauth request.user 在 APIView 中是 AnonymousUser,但在 View 中 is_authenticated - Allauth request.user is AnonymousUser in APIView, but is_authenticated in View Django request.user是空的 - Django request.user is empty 在 Django 和 DRF 中,为什么 api 路由 request.user 会返回一个 AnonymousUser 实例,而 django.contrib.auth.get_user(request) 会返回用户? - In Django and DRF, why would an api route request.user return an AnonymousUser instance, while django.contrib.auth.get_user(request) return the user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM