I have a Javascript application in the front-end, with Wordpress in the back.
The index.php
of Wordpress serves the application if user is logged in, else redirects to login page.
My application attempts to make form submissions via AJAX to Wordpress database.
Currently, I am using Formidable Forms API to submit an entry into a form, but the response I am getting is
code: "jwt_auth_bad_auth_header"
data: { status: 403 }
message: "Authorization header malformed"
My request in JavaScript is as follows:
let submission = await fetch(url, {
method: 'POST',
headers: {
'Content-type': 'application/json',
'Authorization': `Basic ${btoa(APIKEY+':x')}`
},
body: payload
})
The problem is, I know this header should work because I have another application running (similar set up). And I have triple checked the API key itself.
At this point, I am trying to modify the server's response to send back the header, so I can determine what exactly it thinks I am sending.
Alternatively, trying to view any logs Formidable or Wordpress might keep.
How would I go about doing this?
In FrmAPIAppController.php
, there seems to be a promising static method process_response
:
private static function process_response( $response ) {
$body = wp_remote_retrieve_body( $response );
$processed = array( 'message' => '', 'code' => 'FAIL' );
if ( is_wp_error( $response ) ) {
$processed['message'] = $response->get_error_message();
} elseif ( $body == 'error' || is_wp_error( $body ) ) {
$processed['message'] = __( 'You had an HTTP connection error', 'formidable-api' );
} elseif ( isset( $response['response'] ) && isset( $response['response']['code'] ) ) {
$processed['code'] = $response['response']['code'];
$processed['message'] = $response['body'];
}
return $processed;
}
It would be great if I could just console.log
some variables, but I lack knowledge/experience in PHP/Wordpress/backends in general.
Thanks.
WP_DEBUG_LOG
and then useerror_log()
(where you would useconsole.log()
in JS)Bearer <token>
, which appears to be the norm for JWT. What happens if you change the Authorization header to'Bearer ' + APIKEY
?Wrong number of segments
. However, when usingBearer
+ the JWT received fromsimple-jwt-authentication
plug in seems to return yet another 403 resultSorry, you are not allowed to create entries