From 6f13b2218c027494743254013322836dffd4ce84 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Wed, 25 Jun 2025 13:09:05 +0000 Subject: [PATCH] client: Refresh auth tokens when a timer fires Signed-off-by: Michael Tremer --- src/pakfire/client.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/pakfire/client.c b/src/pakfire/client.c index 77ad34b0..31929fcb 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -163,6 +163,9 @@ static int pakfire_client_auth_refresh(struct pakfire_client* self) { if (!*self->auth.refresh_token) return -ENOTSUP; + // Log action + DEBUG(self->ctx, "Refreshing authentication tokens...\n"); + // Create a new transfer r = pakfire_client_xfer_create(&xfer, self, "/api/v1/auth/refresh"); if (r < 0) @@ -202,12 +205,11 @@ ERROR: return r; } -static int pakfire_client_access_timer(sd_event_source* event, uint64_t usec, void* data) { +static int pakfire_client_refresh_timer(sd_event_source* event, uint64_t usec, void* data) { struct pakfire_client* self = data; - DEBUG(self->ctx, "Authentication access timer fired\n"); - - return 0; + // Refresh the authentication tokens + return pakfire_client_auth_refresh(self); } static int pakfire_client_set_access_token(struct pakfire_client* self, const char* token) { @@ -229,7 +231,7 @@ static int pakfire_client_set_access_token(struct pakfire_client* self, const ch // Create the access token timer (unless already done so) if (!self->auth.access_timer) { r = sd_event_add_time_relative(self->loop, &self->auth.access_timer, - CLOCK_MONOTONIC, 0, 0, pakfire_client_access_timer, self); + CLOCK_MONOTONIC, 0, 0, pakfire_client_refresh_timer, self); if (r < 0) { ERROR(self->ctx, "Failed to register the auth access timer: %s\n", strerror(-r)); return r; @@ -247,14 +249,6 @@ static int pakfire_client_set_access_token(struct pakfire_client* self, const ch return 0; } -static int pakfire_client_refresh_timer(sd_event_source* event, uint64_t usec, void* data) { - struct pakfire_client* self = data; - - DEBUG(self->ctx, "Authentication refresh timer fired\n"); - - return 0; -} - static int pakfire_client_set_refresh_token(struct pakfire_client* self, const char* token) { time_t expires_at = -1; int r; -- 2.47.2