From bc2cd99b108b8755a648c3915714e7c0e0771548 Mon Sep 17 00:00:00 2001 From: winter Date: Tue, 17 Dec 2024 15:42:44 +0000 Subject: send auth header when fetching objects (untested again) --- misc/get_remote_object_authenticated.php | 40 ++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 misc/get_remote_object_authenticated.php (limited to 'misc') diff --git a/misc/get_remote_object_authenticated.php b/misc/get_remote_object_authenticated.php new file mode 100644 index 0000000..ba67473 --- /dev/null +++ b/misc/get_remote_object_authenticated.php @@ -0,0 +1,40 @@ +auth?->outboundToken == null) { + // hopefully we can make the request anyway? + $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 + // TODO: use curl instead of file_get_contents + if (str_contains($http_response_header[0], '401') || str_contains($http_response_header[0], '403')) { + // we can't authenticate right now because it's asynchronous + // so i'm choosing to begin the auth process now and return false in the hopes that + // this request will be retried later + $instance?->beginOutboundAuth(); + return false; + } + return $resp; + } + + $context = stream_context_create(['http' => [ + 'header' => 'Authorization: Bearer ' . $instance->auth->outboundToken + ]]); + return file_get_contents($uri, context: $context); +} \ No newline at end of file -- cgit v1.3