'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://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?
Solution 1:[1]
found.
signed it with RS256 on JWT.io with params
HEADER:
{
"alg": "RS256",
"typ": "JWT",
"kid": "your_private_key_id"
}
PAYLOAD:
{
"iss": "your_client_email_of_service_account",
"sub": "your_client_email_of_service_account",
"aud": "https://www.googleapis.com/oauth2/v4/token",
"scope": "https://www.googleapis.com/auth/devstorage.read_only",
"iat": current_unix_time,
"exp": current_unix_time+3600
}
VERIFY SIGNATURE
your_private_key in last field (without \n)
got encoded key
and then
POST /oauth2/v4/token HTTP/1.1
Host: www.googleapis.com
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&assertion=ENCODED_KEY_FROM_JWT.IO
and i got response
{
"access_token": "ya21.c.ElrSBodwuWANeh7Q0-zlXpOxqm9-uEszPElsY2tvoG5aPxRgOkasN5G2sMgj3iosPVbRYk1wXw_DcBnm2FtuNBlZpv_wCC0YS5pWMykR8Ouf5CZg-8OK842rvfk",
"expires_in": 3600,
"token_type": "Bearer"
}
also dont forget give a priveleges to your service account for read in storage
Solution 2:[2]
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:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | intotecho |
