我在IIS上有类似于本教程的Flask应用程序:https://medium.com/@nerdijoe/how-to-deploy-flask-on-iis-with-windows-authentication-733839d657b7但我使用的是httpPlatformCGI而不是FastCGI。使用如下的web.config,我在REMOTE_USER中得到None:
request.environ.get('REMOTE_USER')
web.config:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\python.log" startupTimeLimit="20" processPath="C:\python3\python.exe" arguments="-m flask run --port %HTTP_PLATFORM_PORT%">
</httpPlatform>
<httpErrors errorMode="DetailedLocalOnly" />
<security>
<authentication>
<anonymousAuthentication enabled="false" />
<windowsAuthentication enabled="true" />
</authentication>
</security>
</system.webServer>
</configuration>
如何在IIS上使用Flask获取登录到站点的用户的用户名?
1条答案
按热度按时间dohp0rv51#
web.config看起来不错,只需要将forwardWindowsAuthToken添加到httpPlatform config:
然后,带有令牌的头部将出现在转发的请求上,只需要提取它:
然后在你的Flask应用程序中,假设你使用的是Flask Login的LoginManager: