Diff

mod_http_oauth2/mod_http_oauth2.lua @ 4670:1b81b7269858

mod_http_oauth2: Gracefully handle cache write failure Would previously have thrown an error and probably returned a traceback. This would only happen if a *lot* of authorization codes were requested in a short interval.
author Kim Alvefur <zash@zash.se>
date Thu, 02 Sep 2021 23:06:58 +0200
parent 4669:d3434fd151b5
child 4998:5ab134b7e510
line wrap: on
line diff
--- a/mod_http_oauth2/mod_http_oauth2.lua	Thu Sep 02 23:03:41 2021 +0200
+++ b/mod_http_oauth2/mod_http_oauth2.lua	Thu Sep 02 23:06:58 2021 +0200
@@ -102,11 +102,14 @@
 	local granted_scopes = filter_scopes(granted_jid, params.scope);
 
 	local code = uuid.generate();
-	assert(codes:set(params.client_id .. "#" .. code, {
+	local ok = codes:set(params.client_id .. "#" .. code, {
 		issued = os.time();
 		granted_jid = granted_jid;
 		granted_scopes = granted_scopes;
-	}));
+	});
+	if not ok then
+		return {status_code = 429};
+	end
 
 	local redirect = url.parse(params.redirect_uri);
 	local query = http.formdecode(redirect.query or "");