如何使用Windows身份验证在IIS服务器上的Flask应用中获取当前用户的用户名? [英] How do I get the username of the current user in a Flask app on an IIS server using Windows Authentication?

查看:151
本文介绍了如何使用Windows身份验证在IIS服务器上的Flask应用中获取当前用户的用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows 10的IIS服务器上运行了Flask应用程序(Python 2.7).该服务器配置为使用Windows身份验证.我正在使用HttpPlatformHandler来执行Python代码.

I have a Flask app (Python 2.7) running on an IIS server in Windows 10. The server is configured to use Windows Authentication. I am using an HttpPlatformHandler in order to execute the Python code.

我已验证身份验证是否有效,并且能够看到Kerberos"Negotiate"身份验证标头.但是,我找不到一种方法来访问请求页面的用户的用户名.

I have verified that the authentication is working and am able to see the Kerberos "Negotiate" auth header. However, I cannot find a way to access the username of the user who requested the page.

我尝试打印整个请求标头和请求环境,但它不存在.这篇帖子似乎与我的问题有关,但是其中的代码不正确. 我该怎么做才能将请求者的Windows用户名传递给我的python代码?

I have tried printing the entire request header and request environment and it is not there. This post seems to be about my issue but the code in it is not correct. What can I do to pass the Windows username of the requester to my python code?

我想访问用户的用户名,以限制用户的页面访问并基于用户从页面中删除某些元素.

I would like to access the username of the user in order to both restrict page access by user and remove certain elements from pages based on user.

推荐答案

事实证明,关于

It turns out that the answer on this post works for my configuration as well. I simply downloaded ISAPI_Rewrite 3, copy and pasted the text into httpd.conf, and was able to access the name of the user by calling request.headers.get('X-Remote-User') in my Python code.

这篇关于如何使用Windows身份验证在IIS服务器上的Flask应用中获取当前用户的用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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