diff --git a/nginx-ldap-auth-daemon.py b/nginx-ldap-auth-daemon.py index 5557b7f..e10f0f3 100755 --- a/nginx-ldap-auth-daemon.py +++ b/nginx-ldap-auth-daemon.py @@ -68,7 +68,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 @@ -89,6 +90,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:]) if sys.version_info.major == 3: auth_decoded = auth_decoded.decode("utf-8") user, passwd = auth_decoded.split(':', 1) @@ -274,6 +278,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: