Unknown user
-
Hi
Thanks for the plugin; it all works great, and when I test it in postman it all works fine.
However, if I try to “login” within a wordpress function (using the exact credentials in the body I used in postman), I get an “unknown username” error. I am guessing I am not perhaps calling the login endpoint correctly?
Here’s how I am calling it (I have omitted error checking lines for clarity):
$url = 'https://testsite.net/wp-json/api-bearer-auth/v1/login';
$apw = 'a-test-app-password-for-admin-user-called-testuser' ;
$args = array( ? ? ? ? ? ? ?
? ? 'body' => array(
? ? ? ? "username" => "testuser",
? ? ? ? "password" ?=> $apw,
? ? ? ? "client_name" => "api-bearer",
? ? ),
);
$response = wp_remote_post( $url, $args );
$body = wp_remote_retrieve_body( $response );
$data = json_decode( $body ); // Error checking gives the unknown username error?
$bt = isset( $data->access_token ) ? $data->access_token : null;
$rt = isset( $data->refresh_token ) ? $data->refresh_token : null;Like I said, in postman, doing a POST to the URL above with a body of:
{ “username”: “testuser”, “password”: “a-test-app-password-for-admin-user-called-testuser”, “client_name”: “api-bearer” }
…works fine. Any ideas where I am messing up, please?
Thanks, Adam
- You must be logged in to reply to this topic.