Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to authenticate with Google Service Account credentials using Postman and HTTPS?

I have read these documents:

  • https://cloud.google.com/docs/authentication/getting-started?hl=ru#auth-cloud-implicit-java

  • https://cloud.google.com/storage/docs/reference/libraries?hl=ru

  • https://cloud.google.com/docs/authentication/production?hl=ru#obtaining_and_providing_service_account_credentials_manually

  • https://developers.google.com/identity/protocols/OAuth2ServiceAccount#callinganapi

I have stored the google-secrets.json credentials of the service account. However I can't understand how to send the request with the credentials to get the auth token or api key.

There are only libraries published that do this.

How do I setup authentication with HTTPS in Postman?

like image 354
Aleksandr Podaruev Avatar asked Apr 01 '26 12:04

Aleksandr Podaruev


2 Answers

This is answered very well by Gordon Thompson in the medium article Google Authentication with Postman covering three different methods:

  • Using oauth2l CLI
  • Configuring Postman with OAuth 2 and User Credentials
  • Configuring Postman to use a pre-request script. This will auto-generate Google Access and ID tokens from a Service Account key and save it in Postman. Based on the work of Denis Loginov, the gist is available here:
like image 159
intotecho Avatar answered Apr 04 '26 03:04

intotecho


In the Postman application

  1. Go to Environments module and create a new environment. Let's call it gcp_sa_env
  2. Create a new variable named serviceAccountKey and copy-paste the content of your google-secrets.json in its value. The JSON should contain items like client_email, private_key, token_uri
  3. Go to Collections module and create a new request
  4. Select the created environment (gcp_sa_env) at top-right
  5. In the Pre-request Script copy-paste this Javascript code (gist) enabling to auto-generates a Google OAuth token from a service account key
  6. Add or remove scopes as needed in the SCOPES variable (see documentation here)
  7. In the Authorization module, select Bearer Token as the authorization type and write {{accessToken}} as Token
  8. Configure the rest of the request (method, url, body, etc) and run it
like image 23
Maxime Oriol Avatar answered Apr 04 '26 02:04

Maxime Oriol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!