I am trying to authenticate my app running in App Engine to call a Cloud Run service. To get so I request an OAuth 2 token through the Google Auth library (getIdTokenClient method) as looks to be the recommended approach here https://github.com/googleapis/google-auth-library-nodejs#working-with-id-tokens.
The following error is raised from my app when OAuth 2 is trying to access the Google metadata:
gaxios.ts:91 Mixed Content: The page at 'https://myapp-dev.nw.r.appspot.com/' was loaded over HTTPS, but requested an insecure resource 'http://169.254.169.254/computeMetadata/v1/instance'. This request has been blocked; the content must be served over HTTPS.
Following my piece of code:
const {GoogleAuth} = require('google-auth-library');
const url = 'https://myapp-dev-fvnpywgyfa-nw.a.run.app';
const auth = new GoogleAuth();
const serviceRequestOptions = {
method: 'GET',
headers: {
'Content-Type': 'text/plain',
},
timeout: 3000,
};
try {
// Create a Google Auth client with the Renderer service url as the target audience.
if (!client) client = await auth.getIdTokenClient(url);
// Fetch the client request headers and add them to the service request headers.
// The client request headers include an ID token that authenticates the request.
const clientHeaders = await client.getRequestHeaders();
serviceRequestOptions.headers['Authorization'] =
clientHeaders['Authorization'];
} catch (err) {
throw Error('could not create an identity token: ', err);
}
169.254.169.254
it's using HTTP and not HTTPS as required. Could you please give it a try changing it, so it uses HTTPS? – gso_gabriel