From c58caced838a9a7954e7fefa60c01567bb6bc107 Mon Sep 17 00:00:00 2001 From: winter Date: Tue, 17 Dec 2024 21:04:20 +0000 Subject: winter REPORTEDLY forgot to implement subscribe routes --- misc/get_remote_object_authenticated.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'misc') diff --git a/misc/get_remote_object_authenticated.php b/misc/get_remote_object_authenticated.php index 49aaa59..3c67005 100644 --- a/misc/get_remote_object_authenticated.php +++ b/misc/get_remote_object_authenticated.php @@ -4,12 +4,13 @@ use Digitigrade\GlobalConfig; use Digitigrade\Model\Instance; /** - * Makes an HTTPS GET request to a remote instance, using the corresponding outbound auth token (if any) + * Makes an HTTPS request to a remote instance, using the corresponding outbound auth token (if any) * @param string $uri * @param bool $dontLookUpInstance if true, will skip looking up the Instance, and consequently the auth token + * @param string $method HTTP verb * @return false|string the response data, or false if it failed */ -function get_remote_object_authenticated(string $uri, bool $dontLookUpInstance = false): false|string { +function get_remote_object_authenticated(string $uri, bool $dontLookUpInstance = false, string $method = 'GET'): false|string { if (!str_starts_with($uri, 'https://')) return false; @@ -26,6 +27,7 @@ function get_remote_object_authenticated(string $uri, bool $dontLookUpInstance = if ($instance?->auth?->outboundToken == null) { // hopefully we can make the request anyway? + $context = stream_context_create(['http' => ['method' => $method]]); $resp = file_get_contents($uri); // $http_response_header just poofs into existence . // i don't like this api. i should probably use curl instead. hmm @@ -41,6 +43,7 @@ function get_remote_object_authenticated(string $uri, bool $dontLookUpInstance = } $context = stream_context_create(['http' => [ + 'method' => $method, 'header' => 'Authorization: Bearer ' . $instance->auth->outboundToken ]]); return file_get_contents($uri, context: $context); -- cgit v1.3