From: Michael Tremer Date: Fri, 27 Jun 2025 09:20:35 +0000 (+0000) Subject: client: Tidy up authentication response code X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e98e3c5aa098b2eb082d9f4e7367accbf96abb1b;p=pakfire.git client: Tidy up authentication response code Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/client.c b/src/pakfire/client.c index e02c58dc..1f0c016b 100644 --- a/src/pakfire/client.c +++ b/src/pakfire/client.c @@ -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 {