- response = MHD_create_response_from_callback((uint64_t)strlen(json_object_to_json_string_ext(reply, JSON_C_TO_STRING_PLAIN)), SIZE_RESPONSE_BUFFER, (void*)send_json_cb, reply, (void*)json_object_put);
- afb_hreq_reply(hreq, MHD_HTTP_OK, response, NULL);
+ response = MHD_create_response_from_callback(
+ (uint64_t)strlen(get_json_string(reply)),
+ SIZE_RESPONSE_BUFFER,
+ (void*)send_json_cb,
+ reply,
+ (void*)json_object_put);
+
+ /* handle authorisation feedback */
+ if (error == afb_error_text_invalid_token)
+ afb_hreq_reply(hreq, MHD_HTTP_UNAUTHORIZED, response, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "error=\"invalid_token\"", NULL);
+ else if (error == afb_error_text_insufficient_scope)
+ afb_hreq_reply(hreq, MHD_HTTP_FORBIDDEN, response, MHD_HTTP_HEADER_WWW_AUTHENTICATE, "error=\"insufficient_scope\"", NULL);
+ else
+ afb_hreq_reply(hreq, MHD_HTTP_OK, response, NULL);