return r;
}
+static int pakfire_buildservice_auth_refresh(struct pakfire_buildservice* self) {
+ return 0; // XXX TODO
+}
+
+static int pakfire_buildservice_token_has_expired(const time_t t) {
+ time_t now = -1;
+
+ // Fetch the current time
+ now = time(NULL);
+ if (now < 0)
+ return -errno;
+
+ // We consider the token as expired if there are less than 60 seconds left
+ return (now - t) < 60;
+}
+
+static int pakfire_buildservice_xfer_auth(struct pakfire_buildservice* self, struct pakfire_xfer* xfer) {
+ int r;
+
+ // Fail if not authenticated
+ if (!*self->access_token)
+ return -ENOTSUP;
+
+ // Refresh if the access token has expired
+ if (pakfire_buildservice_token_has_expired(self->access_token_expires_at)) {
+ DEBUG(self->ctx, "The access token has expired. Trying to refresh...\n");
+
+ // Refresh the access token
+ r = pakfire_buildservice_auth_refresh(self);
+ if (r < 0)
+ return r;
+ }
+
+ // Set the access token
+ r = pakfire_xfer_add_header(xfer, "Authorization: Bearer %s", self->access_token);
+ if (r < 0)
+ return r;
+
+ return 0;
+}
+
static int pakfire_buildservice_set_access_token(struct pakfire_buildservice* self, const char* token) {
char expires_at[1024];
int r;
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
+ r = pakfire_buildservice_xfer_auth(service, xfer);
if (r)
goto ERROR;
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
- if (r)
+ r = pakfire_buildservice_xfer_auth(service, xfer);
+ if (r < 0)
goto ERROR;
// Add the filename parameter
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
+ r = pakfire_buildservice_xfer_auth(service, xfer);
if (r)
goto ERROR;
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
+ r = pakfire_buildservice_xfer_auth(service, xfer);
if (r)
goto ERROR;
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
+ r = pakfire_buildservice_xfer_auth(service, xfer);
if (r)
goto ERROR;
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
+ r = pakfire_buildservice_xfer_auth(service, xfer);
if (r)
goto ERROR;
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
+ r = pakfire_buildservice_xfer_auth(service, xfer);
if (r)
goto ERROR;
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
+ r = pakfire_buildservice_xfer_auth(service, xfer);
if (r)
goto ERROR;
goto ERROR;
// Enable authentication
- r = pakfire_xfer_auth(xfer);
+ r = pakfire_buildservice_xfer_auth(service, xfer);
if (r)
goto ERROR;