]> git.ipfire.org Git - pakfire.git/commitdiff
client: Refresh auth tokens when a timer fires
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 13:09:05 +0000 (13:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 25 Jun 2025 13:09:05 +0000 (13:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.c

index 77ad34b026655381c2b42d33e45c08550dd6c16b..31929fcbd063f6756d13d3c162087d2fbbda4ba7 100644 (file)
@@ -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;