Diff

plugins/mod_tokenauth.lua @ 13010:3e454af3615d

mod_tokenauth: Add API to inspect individual grants or all of a user's grants
author Matthew Wild <mwild1@gmail.com>
date Wed, 29 Mar 2023 17:15:33 +0100
parent 13009:a70ff0c524c9
child 13024:7558fd152459
line wrap: on
line diff
--- a/plugins/mod_tokenauth.lua	Wed Mar 29 17:14:45 2023 +0100
+++ b/plugins/mod_tokenauth.lua	Wed Mar 29 17:15:33 2023 +0100
@@ -214,6 +214,24 @@
 	return token_info;
 end
 
+function get_grant_info(username, grant_id)
+	local grant = _get_validated_grant_info(username, grant_id);
+	if not grant then return nil; end
+
+	-- Caller is only interested in the grant, no need to expose token stuff to them
+	grant.tokens = nil;
+
+	return grant;
+end
+
+function get_user_grants(username)
+	local grants = token_store:get(username);
+	if not grants then return nil; end
+	for grant_id, grant in pairs(grants) do
+		grants[grant_id] = _get_validated_grant_info(username, grant);
+	end
+	return grants;
+end
 
 function get_token_info(token)
 	local token_id, token_user, token_host, token_secret = parse_token(token);