aboutsummaryrefslogtreecommitdiffhomepage
path: root/misc/get_remote_object_authenticated.php
diff options
context:
space:
mode:
Diffstat (limited to 'misc/get_remote_object_authenticated.php')
-rw-r--r--misc/get_remote_object_authenticated.php7
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);