Note that there are some explanatory texts on larger screens.

plurals
  1. POhow a python single-thread server can handle multi-client
    primarykey
    data
    text
    <p>I have a server in python that provides pages. The log-in to these pages is done using an IdP (identity provider). So when the user tries to open my server page, he is redirected to the IdP page. In the meanwhile my server starts listening for the IdP response. When the user logs in the in IdP page, the IdP sends data to my server, that handles them and shows my page to the user.</p> <p>The problem is that if multiple clients try to log in, when the server receives the first response from one IdP, all the users will show my page as logged in with the credential of the first user. </p> <p>I mean, when the server starts listening, it's awaiting for everyone. When just the first user logs in, all the user that are awaiting logs with the same credentials.</p> <p>How can I solve this very big problem? Multithreading may help?</p> <p>Here some of the important code. Let's say that i want to load some of the data answered by the idp, into the fields 'name' of the login-form of my page.</p> <pre><code>class Login(django.forms.SelfHandlingForm): def __init__(self, *args, **kwargs): super(Login, self).__init__(*args, **kwargs) response = self.getIdPResponse() self.fields['name'].widget=forms.TextInput(attrs={'value': response['name']}) def getIdPResponse(self): global response response = None timeout = 300 class RequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def do_POST(self): global response self.send_response(200) self.send_header("Content-type", "text/html") self.end_headers() varLen = int(self.headers["Content-Length"]) #response = urlparse.parse_qs(self.rfile.read(varLen)) response = self.rfile.read(varLen) self.wfile.write("Log-in ok! now you can close this page.") httpd = BaseHTTPServer.HTTPServer(('0.0.0.0', 8080), RequestHandler) try: httpd.socket.settimeout(1) except BaseException as e: print e count = 0 '''at this point, the IdP page is already showed to the user ''' while response is None and count &lt; timeout: try: httpd.handle_request() count = count + 1 print 'waiting for the Idp answer...' except Exception as e: print e return response </code></pre> <p>in this way, when an user successfully logs-in, all the user that are waiting to login, will show in the field 'name' the name of the user that first logged in. Obviously I don't want this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload