From b654376e2a63dbd4e1be9530122dc1bb46e2a78f Mon Sep 17 00:00:00 2001 From: Mattias Jiderhamn Date: Fri, 2 Aug 2019 13:21:22 +0200 Subject: [PATCH] Set cookie on successful authentication --- nginx-ldap-auth-daemon.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/nginx-ldap-auth-daemon.py b/nginx-ldap-auth-daemon.py index bdfafff..c26df38 100755 --- a/nginx-ldap-auth-daemon.py +++ b/nginx-ldap-auth-daemon.py @@ -50,7 +50,8 @@ class AuthHandler(BaseHTTPRequestHandler): ctx['action'] = 'performing authorization' auth_header = self.headers.get('Authorization') - auth_cookie = self.get_cookie(ctx['cookiename']) + cookiename = ctx['cookiename'] + auth_cookie = self.get_cookie(cookiename) if auth_cookie != None and auth_cookie != '': auth_header = "Basic " + auth_cookie @@ -71,6 +72,9 @@ class AuthHandler(BaseHTTPRequestHandler): ctx['action'] = 'decoding credentials' try: + if cookiename != None and cookiename != '': + ctx['cookievalue'] = auth_header[6:] + auth_decoded = base64.b64decode(auth_header[6:]) user, passwd = auth_decoded.split(':', 1) @@ -255,6 +259,10 @@ class LDAPAuthHandler(AuthHandler): # Successfully authenticated user self.send_response(200) + cookievalue = ctx['cookievalue'] + if cookievalue != None: + # Cookie.SimpleCookie() causes issues with double quotes + self.send_header("Set-Cookie", "%s=%s" % (ctx['cookiename'], cookievalue)) self.end_headers() except: