简体   繁体   English

如何从另一个应用程序验证Django用户

[英]How to Authenticate a Django user from another application

I want to redirect a user from my Django application to another web application. 我想将用户从Django应用程序重定向到另一个Web应用程序。 Only permitted users can be allowed access to visit the other web application, this permission is set in the Django User model. 只有允许的用户才能访问其他Web应用程序,此权限在Django用户模型中设置。 I want that other web application to verify whether the visited user has permission by querying the Django application using API endpoint. 我希望其他Web应用程序通过使用API​​端点查询Django应用程序来验证访问的用户是否具有权限。

But the other web application no longer has the request.user parameter or other way to authenticate the user based on Django User model (don't wan't him to login again). 但是另一个Web应用程序不再具有request.user参数或其他基于Django User模型对用户进行身份验证的方式(不要让他再次登录)。 Is there any way like setting a cross-domain session cookie or something, i can achieve it? 有什么办法可以设置跨域会话Cookie或其他东西,我可以实现吗?

I did that recently. 我最近做了。

You don't even need the second app to retrieve the users, you can create those users on the fly! 您甚至不需要第二个应用程序即可检索用户,您可以即时创建这些用户!

On the first app, have them click a url that will do a very special GET request to the other app. 在第一个应用程序上,让他们单击一个URL,该URL将对另一个应用程序执行非常特殊的GET请求。

The GET request will encode a few variables with hmac. GET请求将使用hmac编码一些变量。 Name, emails, or any other values you need using a particular SECRET_KEY that both server will share. 使用两个服务器都将共享的特定SECRET_KEY的名称,电子邮件或任何其他值。

In the second app, you can decode that request with the same SECRET_KEY and log in your user. 在第二个应用程序中,您可以使用相同的SECRET_KEY对该请求进行解码,然后登录您的用户。

See : https://docs.python.org/3/library/hmac.html 参见: https : //docs.python.org/3/library/hmac.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 django 中验证来自 mysql 的用户? - How to authenticate User from mysql in django? 如何在python / django中从一台服务器认证到另一台服务器? - How to authenticate from one server to another server in python/django? 如何使用 Django 验证来自 PostgreSQL 的用户表单凭据 - How to authenticate user form credentials from PostgreSQL with Django 如何从iphone到django获取会话并验证用户信息? - How to get session and authenticate user information from iphone to django? 使用 Django 对来自 Flask 的用户进行身份验证 - Using Django to authenticate user from Flask 如何使用密钥对连接的应用程序进行身份验证? Django,Python - How to authenticate connected application with key? Django, Python 如何在Django中对每个应用程序验证用户身份 - How to authenticate users per application in django 如何通过 django rest 框架中的其他微服务对属于另一个数据库的用户进行身份验证? - How can I authenticate a user who belongs to another database through my other microservice in django rest framework? 如何以编程方式对 Django 中的用户进行身份验证? - How can I programmatically authenticate a user in Django? 如何在Django Comment框架中对用户进行身份验证? - How to authenticate user in Django Comment framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM