From d57db8b1dbdd7ef6e121754d2413a1626d4e796e Mon Sep 17 00:00:00 2001 From: Oliver Gorwits Date: Wed, 3 Aug 2022 21:26:12 +0100 Subject: [PATCH] #843 api tokens extended if login again when valid --- lib/App/Netdisco/Web/AuthN.pm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/App/Netdisco/Web/AuthN.pm b/lib/App/Netdisco/Web/AuthN.pm index cc1803a1..e4e7118f 100644 --- a/lib/App/Netdisco/Web/AuthN.pm +++ b/lib/App/Netdisco/Web/AuthN.pm @@ -123,10 +123,14 @@ post '/login' => sub { $user->update({ last_on => \'now()' }); if ($api) { + # from the internals of Dancer::Plugin::Auth::Extensible + my $provider = Dancer::Plugin::Auth::Extensible::auth_provider('users'); header('Content-Type' => 'application/json'); + # if there's a current valid token then reissue it and reset timer $user->update({ token_from => time, - token => \'md5(random()::text)', + ($provider->validate_api_token($user->token) + ? () : (token => \'md5(random()::text)')), })->discard_changes(); return to_json { api_key => $user->token }; }