I am using the below in my wordpress for developing a oauth based application.
WP-API (api generating plugin)
WP API OAuth1 (oauth server)and
WP API client-cli (oauth client library)
at the below url is for the wp client-cli
https://man-sudarshann-1.c9.io/api/
I am getting this error OAuth signature does not match when I click the AUTH button for autherizing the request. I have tried all the fixed for this over the internet. but none helped
signature generated and sent from api client is 3ko8DUsUUEB4Hqaks68vGYnTjQM=
signature generated in server side is 5rPsul6zplhfNvb4o+Mz11O/OyI=
so the below code is failing
if ( ! hash_equals( $signature, $consumer_signature ) ) {
return new WP_Error( 'json_oauth1_signature_mismatch', __( 'OAuth signature does not match' ), array( 'status' => 401 ) );
}
I guess the API console is generating wrong signature. Please help me in solving this issue.
4 Answers
I was facing a similar issue when trying to use Client-CLI with OAuth 1.0a plugin, however I found a solution here on the official repository.
In the file lib/class-wp-json-authentication-oauth1.php
on line 524
, change the following code:
$base_request_uri = rawurlencode( get_home_url( null, parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ), 'http' ) );
to:
$home_url_path = parse_url(get_home_url (null,'','http'), PHP_URL_PATH );
$request_uri_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
if (substr($request_uri_path, 0, strlen($home_url_path)) == $home_url_path) {
$request_uri_path = substr($request_uri_path, strlen($home_url_path));
}
$base_request_uri = rawurlencode( get_home_url( null, $request_uri_path, 'http' ) );
This should solve the problem you are facing.