]> git.ipfire.org Git - pakfire.git/commitdiff
client: Tidy up authentication response code
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 09:20:35 +0000 (09:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 09:20:35 +0000 (09:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/client.c

index e02c58dcb5925f8e90d1d59e2ac858e66c64467b..1f0c016b19b3c8f0cda585738dba77309ef669d2 100644 (file)
@@ -611,17 +611,24 @@ int pakfire_client_set_auth_callback(struct pakfire_client* self,
        return 0;
 }
 
-static int pakfire_client_auth_successful(
-               struct pakfire_client* self, struct json_object* response) {
+static int pakfire_client_auth_response(struct pakfire_xfer* xfer,
+               const pakfire_xfer_response* response, void* data) {
+       struct pakfire_client* self = data;
        const char* refresh_token = NULL;
        const char* access_token = NULL;
        int r;
 
+       // Fail if we encountered an error
+       if (response->error) {
+               ERROR(self->ctx, "Authentication failed\n");
+               return 1;
+       }
+
        // Log action
        DEBUG(self->ctx, "Authentication successful\n");
 
        // Fetch the access token
-       r = pakfire_json_get_string(response, "access_token", &access_token);
+       r = pakfire_json_get_string(response->data, "access_token", &access_token);
        if (r < 0) {
                ERROR(self->ctx, "Failed to fetch the access token: %s\n", strerror(-r));
                return r;
@@ -633,7 +640,7 @@ static int pakfire_client_auth_successful(
                return r;
 
        // Fetch the refresh token
-       r = pakfire_json_get_string(response, "refresh_token", &refresh_token);
+       r = pakfire_json_get_string(response->data, "refresh_token", &refresh_token);
        if (r < 0) {
                ERROR(self->ctx, "Failed to fetch the refresh token: %s\n", strerror(-r));
                return r;
@@ -648,21 +655,6 @@ static int pakfire_client_auth_successful(
        return pakfire_client_ready(self);
 }
 
-static int pakfire_client_auth_response(struct pakfire_xfer* xfer,
-               const pakfire_xfer_response* response, void* data) {
-       struct pakfire_client* client = data;
-
-       switch (response->error) {
-               case PAKFIRE_XFER_OK:
-                       return pakfire_client_auth_successful(client, response->data);
-
-               default:
-                       ERROR(client->ctx, "Authentication failed\n");
-       }
-
-       return 0;
-}
-
 int pakfire_client_auth_user(struct pakfire_client* self, const char* password) {
        struct pakfire_xfer* xfer = NULL;
        struct {