summaryrefslogtreecommitdiff
path: root/postgresqleu/auth.py
diff options
context:
space:
mode:
authorMagnus Hagander2015-04-21 12:39:49 +0000
committerMagnus Hagander2015-04-21 12:39:49 +0000
commit676a5dee76ab1943f32e3778032f3a99c95e293e (patch)
treec45a7305a5e3e1f5429a68743f5910e3afa0b4fb /postgresqleu/auth.py
parent22ee52b4bbe7681039a15af61a92e744a0981932 (diff)
Return proper errorcodes from auth plugin
Instead of raising an exception which will cause both a server log and an email to be sent, return a proper http 400 message when the incoming authentication request is bad. This will also show the proper error message to the client, instead of a generic internal server error.
Diffstat (limited to 'postgresqleu/auth.py')
-rw-r--r--postgresqleu/auth.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/postgresqleu/auth.py b/postgresqleu/auth.py
index 84e41b7a..da1194b2 100644
--- a/postgresqleu/auth.py
+++ b/postgresqleu/auth.py
@@ -82,9 +82,9 @@ def auth_receive(request):
return HttpResponseRedirect('/')
if not request.GET.has_key('i'):
- raise Exception("Missing IV")
+ return HttpResponse("Missing IV in url!", status=400)
if not request.GET.has_key('d'):
- raise Exception("Missing data!")
+ return HttpResponse("Missing data in url!", status=400)
# Set up an AES object and decrypt the data we received
decryptor = AES.new(base64.b64decode(settings.PGAUTH_KEY),
@@ -95,12 +95,12 @@ def auth_receive(request):
# Now un-urlencode it
try:
data = urlparse.parse_qs(s, strict_parsing=True)
- except ValueError, e:
- raise Exception("Invalid encrypted data received.")
+ except ValueError:
+ return HttpResponse("Invalid encrypted data received.", status=400)
# Check the timestamp in the authentication
if (int(data['t'][0]) < time.time() - 10):
- raise Exception("Authentication token too old.")
+ return HttpResponse("Authentication token too old.", status=400)
# Update the user record (if any)
try:
@@ -162,14 +162,14 @@ We apologize for the inconvenience.
try:
rdata = urlparse.parse_qs(s, strict_parsing=True)
except ValueError:
- raise Exception("Invalid encrypted data received.")
+ return HttpResponse("Invalid encrypted data received.", status=400)
if rdata.has_key('r'):
# Redirect address
return HttpResponseRedirect(rdata['r'][0])
# No redirect specified, see if we have it in our settings
if hasattr(settings, 'PGAUTH_REDIRECT_SUCCESS'):
return HttpResponseRedirect(settings.PGAUTH_REDIRECT_SUCCESS)
- raise Exception("Authentication successful, but don't know where to redirect!")
+ return HttpResponse("Authentication successful, but don't know where to redirect!", status=500)
# Perform a search in the central system. Note that the results are returned as an