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