# HG changeset patch # User Matthew Wild # Date 1680106533 -3600 # Node ID 3e454af3615d790a84969c6248109dee15d40b02 # Parent a70ff0c524c986ef31957eacc10d9192c3ba12a0 mod_tokenauth: Add API to inspect individual grants or all of a user's grants diff -r a70ff0c524c9 -r 3e454af3615d plugins/mod_tokenauth.lua --- 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);