+/**
+ * Parse a JWT and return the respective claim value as Attribute
+ *
+ * @param attest the jwt attestation
+ * @param claim the name of the claim in the JWT
+ *
+ * @return a GNUNET_RECLAIM_Attribute, containing the new value
+ */
+struct GNUNET_RECLAIM_AttributeList *
+jwt_parse_attributes (void *cls,
+ const struct GNUNET_RECLAIM_Attestation *attest)
+{
+ char *jwt_string;
+ struct GNUNET_RECLAIM_AttributeList *attrs;
+ char delim[] = ".";
+ char *val_str = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Parsing JWT attributes.\n");
+ char *decoded_jwt;
+ json_t *json_val;
+ json_error_t *json_err = NULL;
+
+ if (GNUNET_RECLAIM_ATTESTATION_TYPE_JWT != attest->type)
+ return NULL;
+ attrs = GNUNET_new (struct GNUNET_RECLAIM_AttributeList);
+
+ jwt_string = GNUNET_strdup (attest->data);
+ const char *jwt_body = strtok (jwt_string, delim);
+ jwt_body = strtok (NULL, delim);
+ GNUNET_STRINGS_base64_decode (jwt_body, strlen (jwt_body),
+ (void **) &decoded_jwt);
+ json_val = json_loads (decoded_jwt, JSON_DECODE_ANY, json_err);
+ const char *key;
+ json_t *value;
+ json_object_foreach (json_val, key, value) {
+ val_str = json_dumps (value, JSON_ENCODE_ANY);
+ GNUNET_RECLAIM_attribute_list_add (attrs,
+ key,
+ NULL,
+ GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING,//FIXME
+ val_str,
+ strlen (val_str));
+ GNUNET_free (val_str);
+ }
+ GNUNET_free (jwt_string);
+ //FIXME needed??
+ return attrs;
+}
+
+
+