admin管理员组文章数量:1167245
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.
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.
Share Improve this question asked Jul 3, 2019 at 6:58 achacttnachacttn 1011 bronze badge 5 |1 Answer
Reset to default 0I'm facing the same issue now. There is a conflict between Formidable API and JWT Authentication for Wordpress Rest API plugin, none of which offer ways to deactivate authentication on specific routes.
本文标签: pluginsModifying server39s response to API endpoint
版权声明:本文标题:plugins - Modifying server's response to API endpoint 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1737579758a1997437.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
WP_DEBUG_LOG
and then useerror_log()
(where you would useconsole.log()
in JS) – kero Commented Jul 3, 2019 at 7:54Bearer <token>
, which appears to be the norm for JWT. What happens if you change the Authorization header to'Bearer ' + APIKEY
? – Jacob Peattie Commented Jul 3, 2019 at 14:28Wrong 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
– achacttn Commented Jul 4, 2019 at 0:25