Created
April 16, 2022 13:32
-
-
Save ibrezm1/1a73c6e5336e1fbc4f14e2404e8d3e10 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Sample Cloud execution on local | |
| # pip install google-auth | |
| # pip install --upgrade google-auth | |
| import os | |
| import json | |
| import requests | |
| import google.oauth2.id_token | |
| import google.auth.transport.requests | |
| function_url = 'https://us-central1-zeta-yen-319702.cloudfunctions.net/function-1' | |
| os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = './zeta-yen-319702-8ea3f83d2b69.json' | |
| request = google.auth.transport.requests.Request() | |
| audience = function_url | |
| TOKEN = google.oauth2.id_token.fetch_id_token(request, audience) | |
| r = requests.post( | |
| function_url, | |
| headers={'Authorization': f"Bearer {TOKEN}", "Content-Type": "application/json"}, | |
| data=json.dumps({"name": "test"}) # possible request parameters | |
| ) | |
| print (r.status_code, r.json() ) | |
| #curl -m 70 -X POST https://us-central1-zeta-yen-319702.cloudfunctions.net/function-1 \ | |
| #-H "Authorization:bearer $(gcloud auth print-identity-token)" \ | |
| #-H "Content-Type:application/json" \ | |
| #-d '{ | |
| # "name": "Hello World" | |
| #}' | |
| # |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment