Comparison

plugins/mod_tokenauth.lua @ 13275:5db61e0dfc62

mod_tokenauth: Save grant after removing expired tokens Ensures the periodic cleanup really does remove expired tokens.
author Kim Alvefur <zash@zash.se>
date Sat, 21 Oct 2023 12:33:55 +0200
parent 13274:ddfe07041fc5
child 13276:c34266c061c9
comparison
equal deleted inserted replaced
13274:ddfe07041fc5 13275:5db61e0dfc62
165 module:log("debug", "Token grant without tokens, cleaning up"); 165 module:log("debug", "Token grant without tokens, cleaning up");
166 token_store:set_key(username, grant.id, nil); 166 token_store:set_key(username, grant.id, nil);
167 return nil, "invalid"; 167 return nil, "invalid";
168 end 168 end
169 for secret_hash, token_info in pairs(grant.tokens) do 169 for secret_hash, token_info in pairs(grant.tokens) do
170 local found_expired = false
170 if token_info.expires and token_info.expires < now then 171 if token_info.expires and token_info.expires < now then
171 module:log("debug", "Token has expired, cleaning it up"); 172 module:log("debug", "Token has expired, cleaning it up");
172 grant.tokens[secret_hash] = nil; 173 grant.tokens[secret_hash] = nil;
174 found_expired = true;
175 end
176 if found_expired then
177 token_store:set_key(username, grant.id, nil);
173 end 178 end
174 end 179 end
175 180
176 if not grant.expires and next(grant.tokens) == nil and grant.accessed + empty_grant_lifetime < now then 181 if not grant.expires and next(grant.tokens) == nil and grant.accessed + empty_grant_lifetime < now then
177 module:log("debug", "Token grant has no tokens, discarding"); 182 module:log("debug", "Token grant has no tokens, discarding");