diff options
| author | winter | 2024-12-17 21:04:20 +0000 |
|---|---|---|
| committer | winter | 2024-12-17 21:04:20 +0000 |
| commit | c58caced838a9a7954e7fefa60c01567bb6bc107 (patch) | |
| tree | c68d6bb8f7c8b9636485e3f52f9a7b856316e0de /misc/get_remote_object_authenticated.php | |
| parent | 10793d22df72f12f2f14c730c09b5018b5b6e63a (diff) | |
winter REPORTEDLY forgot to implement subscribe routes
Diffstat (limited to 'misc/get_remote_object_authenticated.php')
| -rw-r--r-- | misc/get_remote_object_authenticated.php | 7 |
1 files changed, 5 insertions, 2 deletions
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); |
