I need to cURL a web app hosted behind IAP on GCP.
Normally, users log in through IAP and use the web app, but I need to run some cURL commands (interactive and non-interactive) that hit the web app URLs (for example: https://myapp.com/get_pics/1)
I cannot figure out how to get a Bearer token from GCP that I can use in the authorization header for cURL.
I can set up a service account with "IAP Secured Web App User" role and I have the JSON key for this service account, but I am not sure where to go after that to get a proper Bearer token that IAP will accept.
I cannot figure out how to get a Bearer token from GCP that I can use in the authorization header for cURL.
According with the Google Public Documentation
Bearer Token OIDC
This document also includes code samples to:
And in this link you can find more information about Verify Bearer Token in GCP
Bearer Token Auth
After some research I found two pages that describe How to provide your service account authentication as a Bearer token and How to send Curl POST request with Bearer Token Authorization Header.
The first one is part of the Google Developers public documentation, and describes the process to obtain a Bearer token with your service account.
And in this link you will find information and examples about Curl Request With Bearer Token Authorization Header
For IAP you need to provide a OIDC identity token. You can use
gcloud
to create it for you, or use any other mean as described in Programmatic authentication.I assume you have gcloud, so I'll show you how to use that: