nginxinc / nginx-ldap-auth

Example of LDAP authentication using ngx_http_auth_request_module
BSD 2-Clause "Simplified" License
678 stars 202 forks source link

backend-sample-app.py concat issue on Python 3 #76

Open joshmarvel opened 4 years ago

joshmarvel commented 4 years ago

backend-sample-app.py line 124 attempts to concatinate bytes literals and strings. On line 123 convert enc from a string to bytes literal. I purpose the following fix. - enc = enc.decode() + enc = bytes(enc.decode(), encoding='utf-8') self.send_header('Set-Cookie', b'nginxauth=' + enc + b'; httponly')

bmbouter commented 4 years ago

I tried your patch but it didn't work for me (although maybe for you). The following patch did work for me:

diff --git a/backend-sample-app.py b/backend-sample-app.py
index 970c3ab..0b7b17b 100755
--- a/backend-sample-app.py
+++ b/backend-sample-app.py
@@ -121,7 +121,7 @@ class AppHandler(BaseHTTPRequestHandler):
             enc = base64.b64encode(ensure_bytes(user + ':' + passwd))
             if sys.version_info.major == 3:
                 enc = enc.decode()
-            self.send_header('Set-Cookie', b'nginxauth=' + enc + b'; httponly')
+            self.send_header('Set-Cookie', 'nginxauth=' + enc + '; httponly')

             self.send_header('Location', target)
             self.end_headers()