Home NewsX California Consumer Privacy Act (CCPA) Opt-Out Icon

California Consumer Privacy Act (CCPA) Opt-Out Icon

by info.odysseyx@gmail.com
0 comment 4 views


problem : Deploying a Python Flask application to IIS can be a smooth process, but sometimes you will run into issues that require careful troubleshooting. One such issue is that Flask applications fail to retrieve the Windows Authentication user ID when using HttpPlatformHandler. While we were able to retrieve the user details successfully using WFastCGI, we were not able to do so using HttpPlatformHandler. Let’s take a look at how to retrieve the user details in such a scenario.

Some pointers:

Moving from WFastCGI to HttpPlateFormHandlers: WFastCGI is no longer maintained, see here.

Configuring a Python Web App for IIS – Visual Studio (Windows) | Microsoft Learn

pradeepsharma_0-1724942153250.png

Configuration adjustment:

The key steps are to enable: ForwardWindowsAuthToken In the options Http platform handler Configuration. This setting passes the Windows Authentication token to your application so that you can access and process it within your code.

PradeepSharma_1-1724942153254.png

Code implementation:

After adjusting the configuration, you can update your Flask application code to retrieve the Windows Authentication user ID. The following code snippet shows how this can be done.

import flask from flask, request, render_template

Import os

import win32api

Import win32security

Create create_app():

app = flask(__name__)

@app.route(“https://techcommunity.microsoft.com/”)

def hello_world():

s_vars = request.environment

user = os.environ.get(‘USERNAME’)

handle_str = request.header[‘x-iis-windowsauthtoken’]

handle = int(handle_string, 16)

win32security.ImpersonateLoggedOnUser(handle)

user1 = win32api.GetUserName()

win32api.CloseHandle(handle)

f returns “Hello World!: {user1}”.

Return the app

This code snippet demonstrates how to impersonate a logged in user and retrieve their username using the win32api and win32security modules. The key element here is the x-iis-windowsauthtoken header, which contains the Windows authentication token passed in from the HttpPlatformHandler.

Dependency Guarantee:

Make sure you have the pywin32 package installed, as it provides the functionality needed to interact with the Windows API from within the Python environment.

pradeepsharma_2-1724942153254.jpeg

For more information, see the following resources:





Source link

You may also like

Leave a Comment

Our Company

Welcome to OdysseyX, your one-stop destination for the latest news and opportunities across various domains.

Newsletter

Subscribe my Newsletter for new blog posts, tips & new photos. Let's stay updated!

Laest News

@2024 – All Right Reserved. Designed and Developed by OdysseyX