Any ideas on this?
z_fetch_url(...) refuses to deliver if the API needs a login. It results in "Invalid consumer key".
Example for localhost (in a VM)... The example produces the same result in Hubzilla dev and Osada dev.
Basically I want to do a
curl -u a:. http://localhost/api/z/1.0/files
The curl works. "a" is the user and "." is the password.
Using the header "http_auth" works $url = "http://localhost/api/z/1.0/files";
$headers = [
'X-API-Token' => random_string(),
'X-API-Request' => $url,
'Host' => \App::get_hostname(),
'(request-target)' => "/api/z/1.0/files",
];
$opts = [ 'headers' => $headers , 'http_auth' => 'a:.' ];
$x = z_fetch_url($url,true,0,$opts);
The example sets the user and passwords for curl with 'http_auth' => 'a:.'
For obvious reasons this is not what I want. I tried it only because the following does not work...
Using \Zotlabs\Web\HTTPSig for authentication does not workThis is how File_import.php in addon file_import uses z_fetch_url(...)
$url = "http://localhost/api/z/1.0/files";
$headers = [
'X-API-Token' => random_string(),
'X-API-Request' => $url,
'Host' => \App::get_hostname(),
'(request-target)' => "/api/z/1.0/files",
];
$channel = \App::get_channel();
$headers = \Zotlabs\Web\HTTPSig::create_sig($headers,$channel['channel_prvkey'], channel_url($channel),true,'sha512');
$opts = [ 'headers' => $headers ];
$x = z_fetch_url($url,true,0,$opts);
The logfile of Osada prints out more details...
2018-11-20T21:53:53Z:LOG_INFO:66994785cf:api_auth.php:72:api_login: Invalid consumer key
2018-11-20T21:53:53Z:LOG_INFO:66994785cf:HTTPSig.php:163:verify: verify failed for http://localhost/channel/a alg=sha512
2018-11-20T21:53:53Z:LOG_INFO:66994785cf:HTTPSig.php:165:verify: affected sigblock: Array
(
[keyId] => http://localhost/channel/a
[algorithm] => rsa-sha512
[headers] => Array
(
[0] => x-api-token
[1] => x-api-request
[2] => host
[3] => (request-target)
)
[signature] => igV5hfWhhuj05mtckUFCVgyc2yVeCueuePe9U8mYgS7+8O6ku3jV+wgqZQnyFV98gRpu82wuZewaLdTf4Dywrii8q4zvUu8Djk8cVsEBHlhY6o52cHC4tmOc/56J3EpepFWzsBotshDRSszuJP+Hd2UatJZQjfRGpsMs0ZZ2L4pyXD7urtfCX5sM7U6Xp5q20nE9sPvXzHvgm+lxbOm5oCfq9lL6LkhL+yp35+eiEcj6RWjkqdaGQjyi6hloDCB87RHwCMmqwIRMG1vXZgjBM1QbG1oQkSvtXVk7ZV7FpLelBcanKmuXu0T+8frw6Vmv3QjIhiRNkzuOs0XAabuU7PgIqP5Hr0YdW5bI1ZxK8AS1DTAFTpQq9FoFHaDRqq0LzwMnIHHiO/w/1qpD8yHo6DhLMaHahdBb1/2BzigSbAYU/NaPY/9TjE/2meNfbLUwkyM+PLivTILpQACQx4CtXWoc1EgYf/dtqeYZCNWJrk9is6e02lvZCmhNWCAXW4ZvXPHiZLpjeFMqc2ydsRnkXDQEtO0dOtXve16uSPdpATRH2WFbBnI9UMOsdC3iRCa/ECQeHfZ62LUUlksLWlOWll7xM+Z5RdbSY3XSIfCZzuKUFu1IlcQ8Rwx1UUAGYqq2CeRBc2WgrcOtRrzMBroiMpUcRMXBLXnp1JmXU9CiYd0=
)
2018-11-20T21:53:53Z:LOG_INFO:66994785cf:HTTPSig.php:166:verify: headers: Array
(
[(request-target)] => get /api/z/1.0/files
[content-type] =>
[content-length] =>
[host] => localhost
[user-agent] => Mozilla/5.0 (compatible; zot)
[accept] => */*
[x-api-token] => ddfc29cc2f25f2ad6eeb2fa72c95bcacd0b331674b55b871e5b869f8495060d9
[x-api-request] => http://localhost/api/z/1.0/files
[authorization] => Signature keyId="http://localhost/channel/a",algorithm="rsa-sha512",headers="x-api-token x-api-request host (request-target)",signature="igV5hfWhhuj05mtckUFCVgyc2yVeCueuePe9U8mYgS7+8O6ku3jV+wgqZQnyFV98gRpu82wuZewaLdTf4Dywrii8q4zvUu8Djk8cVsEBHlhY6o52cHC4tmOc/56J3EpepFWzsBotshDRSszuJP+Hd2UatJZQjfRGpsMs0ZZ2L4pyXD7urtfCX5sM7U6Xp5q20nE9sPvXzHvgm+lxbOm5oCfq9lL6LkhL+yp35+eiEcj6RWjkqdaGQjyi6hloDCB87RHwCMmqwIRMG1vXZgjBM1QbG1oQkSvtXVk7ZV7FpLelBcanKmuXu0T+8frw6Vmv3QjIhiRNkzuOs0XAabuU7PgIqP5Hr0YdW5bI1ZxK8AS1DTAFTpQq9FoFHaDRqq0LzwMnIHHiO/w/1qpD8yHo6DhLMaHahdBb1/2BzigSbAYU/NaPY/9TjE/2meNfbLUwkyM+PLivTILpQACQx4CtXWoc1EgYf/dtqeYZCNWJrk9is6e02lvZCmhNWCAXW4ZvXPHiZLpjeFMqc2ydsRnkXDQEtO0dOtXve16uSPdpATRH2WFbBnI9UMOsdC3iRCa/ECQeHfZ62LUUlksLWlOWll7xM+Z5RdbSY3XSIfCZzuKUFu1IlcQ8Rwx1UUAGYqq2CeRBc2WgrcOtRrzMBroiMpUcRMXBLXnp1JmXU9CiYd0="
)
2018-11-20T21:53:53Z:LOG_INFO:66994785cf:HTTPSig.php:167:verify: server: Array
(
[REDIRECT_REMOTE_USER] => Signature keyId="http://localhost/channel/a",algorithm="rsa-sha512",headers="x-api-token x-api-request host (request-target)",signature="igV5hfWhhuj05mtckUFCVgyc2yVeCueuePe9U8mYgS7+8O6ku3jV+wgqZQnyFV98gRpu82wuZewaLdTf4Dywrii8q4zvUu8Djk8cVsEBHlhY6o52cHC4tmOc/56J3EpepFWzsBotshDRSszuJP+Hd2UatJZQjfRGpsMs0ZZ2L4pyXD7urtfCX5sM7U6Xp5q20nE9sPvXzHvgm+lxbOm5oCfq9lL6LkhL+yp35+eiEcj6RWjkqdaGQjyi6hloDCB87RHwCMmqwIRMG1vXZgjBM1QbG1oQkSvtXVk7ZV7FpLelBcanKmuXu0T+8frw6Vmv3QjIhiRNkzuOs0XAabuU7PgIqP5Hr0YdW5bI1ZxK8AS1DTAFTpQq9FoFHaDRqq0LzwMnIHHiO/w/1qpD8yHo6DhLMaHahdBb1/2BzigSbAYU/NaPY/9TjE/2meNfbLUwkyM+PLivTILpQACQx4CtXWoc1EgYf/dtqeYZCNWJrk9is6e02lvZCmhNWCAXW4ZvXPHiZLpjeFMqc2ydsRnkXDQEtO0dOtXve16uSPdpATRH2WFbBnI9UMOsdC3iRCa/ECQeHfZ62LUUlksLWlOWll7xM+Z5RdbSY3XSIfCZzuKUFu1IlcQ8Rwx1UUAGYqq2CeRBc2WgrcOtRrzMBroiMpUcRMXBLXnp1JmXU9CiYd0="
[REDIRECT_STATUS] => 200
[HTTP_HOST] => localhost
[HTTP_USER_AGENT] => Mozilla/5.0 (compatible; zot)
[HTTP_ACCEPT] => */*
[HTTP_X_API_TOKEN] => ddfc29cc2f25f2ad6eeb2fa72c95bcacd0b331674b55b871e5b869f8495060d9
[HTTP_X_API_REQUEST] => http://localhost/api/z/1.0/files
[PATH] => /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[SERVER_SIGNATURE] => <address>Apache/2.4.25 (Debian) Server at localhost Port 80</address>
[SERVER_SOFTWARE] => Apache/2.4.25 (Debian)
[SERVER_NAME] => localhost
[SERVER_ADDR] => ::1
[SERVER_PORT] => 80
[REMOTE_ADDR] => ::1
[DOCUMENT_ROOT] => /var/www/html
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => /var/www/html
[SERVER_ADMIN] => webmaster@localhost
[SCRIPT_FILENAME] => /var/www/html/index.php
[REMOTE_PORT] => 51508
[REDIRECT_URL] => /api/z/1.0/files
[REDIRECT_QUERY_STRING] => req=api/z/1.0/files
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => req=api/z/1.0/files
[REQUEST_URI] => /api/z/1.0/files
[SCRIPT_NAME] => /index.php
[PHP_SELF] => /index.php
[REQUEST_TIME_FLOAT] => 1542750833.929
[REQUEST_TIME] => 1542750833
[HTTP_AUTHORIZATION] => Signature keyId="http://localhost/channel/a",algorithm="rsa-sha512",headers="x-api-token x-api-request host (request-target)",signature="igV5hfWhhuj05mtckUFCVgyc2yVeCueuePe9U8mYgS7+8O6ku3jV+wgqZQnyFV98gRpu82wuZewaLdTf4Dywrii8q4zvUu8Djk8cVsEBHlhY6o52cHC4tmOc/56J3EpepFWzsBotshDRSszuJP+Hd2UatJZQjfRGpsMs0ZZ2L4pyXD7urtfCX5sM7U6Xp5q20nE9sPvXzHvgm+lxbOm5oCfq9lL6LkhL+yp35+eiEcj6RWjkqdaGQjyi6hloDCB87RHwCMmqwIRMG1vXZgjBM1QbG1oQkSvtXVk7ZV7FpLelBcanKmuXu0T+8frw6Vmv3QjIhiRNkzuOs0XAabuU7PgIqP5Hr0YdW5bI1ZxK8AS1DTAFTpQq9FoFHaDRqq0LzwMnIHHiO/w/1qpD8yHo6DhLMaHahdBb1/2BzigSbAYU/NaPY/9TjE/2meNfbLUwkyM+PLivTILpQACQx4CtXWoc1EgYf/dtqeYZCNWJrk9is6e02lvZCmhNWCAXW4ZvXPHiZLpjeFMqc2ydsRnkXDQEtO0dOtXve16uSPdpATRH2WFbBnI9UMOsdC3iRCa/ECQeHfZ62LUUlksLWlOWll7xM+Z5RdbSY3XSIfCZzuKUFu1IlcQ8Rwx1UUAGYqq2CeRBc2WgrcOtRrzMBroiMpUcRMXBLXnp1JmXU9CiYd0="
)
2018-11-20T21:53:53Z:LOG_INFO:5b50b8bc94:Mod_Flashcards.php:669:importBox: no api response, error: body: This api requires login