I'm trying to upload files to a Google Cloud Storage bucket from a Ballerina application.
Right now, the only way I’ve found to authenticate is by manually generating an access token using a service-account.json file from the Google Cloud Console.
My question: Is there a way in Ballerina to:
- Load a service account JSON key
- Request a Google OAuth 2.0 access token
- Use that token to interact with GCS APIs
If so, what’s the right way to do this using Ballerina’s built-in modules?
What I tried:
- I used Ballerina’s
httpto send a POST request to GCS. - I passed an access token (manually generated via
gcloud auth application-default print-access-token) in theAuthorizationheader. - It works, but the access token expires quickly and must be regenerated manually.
What I want: I’d like to programmatically authenticate using a service account key or some supported method in Ballerina, so the token can be generated or refreshed within the app.