return r;
// Fetch the expiry time
- self->access_token_expires_at = pakfire_jwt_expires_at(self->ctx, self->access_token);
- if (self->access_token_expires_at < 0)
+ self->access_token_expires_at = pakfire_jwt_expires_at(self->access_token);
+ if (self->access_token_expires_at < 0) {
+ ERROR(self->ctx, "Failed to fetch the JWT expiry time: %s\n", strerror(-r));
return self->access_token_expires_at;
+ }
// Format the expiry time
r = pakfire_strftime(expires_at, "%Y-%m-%dT%H:%M:%SZ", self->access_token_expires_at);
return r;
// Fetch the expiry time
- self->refresh_token_expires_at = pakfire_jwt_expires_at(self->ctx, self->refresh_token);
- if (self->refresh_token_expires_at < 0)
+ self->refresh_token_expires_at = pakfire_jwt_expires_at(self->refresh_token);
+ if (self->refresh_token_expires_at < 0) {
+ ERROR(self->ctx, "Failed to fetch the JWT expiry time: %s\n", strerror(-r));
return self->refresh_token_expires_at;
+ }
// Format the expiry time
r = pakfire_strftime(expires_at, "%Y-%m-%dT%H:%M:%SZ", self->refresh_token_expires_at);
#include <json.h>
#include <pakfire/base64.h>
-#include <pakfire/ctx.h>
#include <pakfire/json.h>
#include <pakfire/jwt.h>
return r;
}
-int pakfire_jwt_payload(struct pakfire_ctx* ctx, const char* token, struct json_object** payload) {
- char* error = NULL;
+int pakfire_jwt_payload(const char* token, struct json_object** payload) {
char* p = NULL;
size_t l = 0;
int r;
// Decode the payload
r = pakfire_jwt_decode_payload(&p, &l, token);
- if (r < 0) {
- ERROR(ctx, "Failed to decode the JWT payload: %s\n", strerror(-r));
- goto ERROR;
- }
+ if (r < 0)
+ return r;
// Parse the JSON
- r = pakfire_json_parse(payload, &error, p, l);
- if (r < 0) {
- ERROR(ctx, "Failed to parse JSON payload: %s\n", error);
- goto ERROR;
- }
-
-ERROR:
- if (error)
- free(error);
+ r = pakfire_json_parse(payload, NULL, p, l);
+ if (r < 0)
+ return r;
return 0;
}
-time_t pakfire_jwt_expires_at(struct pakfire_ctx* ctx, const char* token) {
+time_t pakfire_jwt_expires_at(const char* token) {
struct json_object* payload = NULL;
time_t expires_at = -1;
int r;
// Parse the payload
- r = pakfire_jwt_payload(ctx, token, &payload);
+ r = pakfire_jwt_payload(token, &payload);
if (r < 0)
goto ERROR;
#include <json.h>
-#include <pakfire/ctx.h>
+int pakfire_jwt_payload(const char* token, struct json_object** payload);
-int pakfire_jwt_payload(struct pakfire_ctx* ctx,
- const char* token, struct json_object** payload);
-
-time_t pakfire_jwt_expires_at(struct pakfire_ctx* ctx, const char* token);
+time_t pakfire_jwt_expires_at(const char* token);
#endif /* PAKFIRE_JWT_H */