Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1854

How to authenticate to Google Cloud Run service with PHP from external server

$
0
0

I am in the same situation as many others. I am able to easily connect to my Google Cloud Run service from my computer with the gcloud installation, like this:

curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" https://my_service_url

And there it stops, as I cannot transfer the communication to the server of my non-Google web host. I have tried for days without any clear instructions or tutorials, or at least my findings do not work or are outdated. My setup requires the use of PHP, and I have already acquired the json key for the service account having the Cloud Run Invoker rights.

Could somebody help and give an example for the authentication in the described context. With brief explanations of every line, because I got confused due to the many wrong solutions why I lost the track and confidence. If it is advisable to check that is the previous authentication still in force, that can also be implemented to avoid unecessary re-authentications.

About my current situation. This is one of the Stackoverflow sources I have tried without luck. Notice how one of the comments says that the answer is actually incomplete.

I have installed the google/apiclient on my Cpanel, and here is one of my authentication attempts (to prepare an authentication bearer for an HTTP request):

require_once $autoloadpath;$client = new Google\Client();$client->setAuthConfig($jsonkeypath);$client->useApplicationDefaultCredentials();$client->setScopes('https://www.googleapis.com/auth/cloud-platform');$client->setApplicationName("app_name");$access_token = $client->fetchAccessTokenWithAssertion();$bearerToken = $access_token['id_token']; //THIS LINE SEEMS TO BE PROBLEMATIC AT LEAST

The above line gave the following warning

PHP Warning: Undefined array key "id_token" in /workspace/index.php

I am unsure is this a correct approach at all, but this is my latest attempt to make bearers for the HTTP requests. It is notable how the google/apiclient documentation does not even mention the bearer in the examples, one of the fundamental elements in the HTTP communication. This makes even more unsure that is my overall approach correct.


Viewing all articles
Browse latest Browse all 1854

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>