Skip to content

Commit f46d0c5

Browse files
committed
updated code
1 parent 36cc336 commit f46d0c5

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

functions-python/reverse_geolocation/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ google-cloud-storage
2020
google-cloud-tasks
2121
google-cloud-datastore
2222
google-cloud-pubsub
23+
google-auth
2324

2425
# Additional packages for this function
2526
pandas

functions-python/reverse_geolocation/src/reverse_geolocation_processor.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
from shared.helpers.logger import get_logger
4040

4141
import google.auth
42-
from google.auth.transport.requests import Request
4342
import google.auth.transport.requests
4443

4544

@@ -386,22 +385,15 @@ def extract_location_aggregates(
386385
if not refresh_url:
387386
raise ValueError("FUNCTION_URL_REFRESH_MV environment variable is not set")
388387

389-
# Fetch default credentials
390-
credentials, _ = google.auth.default()
388+
# Create an authorized request
389+
auth_req = google.auth.transport.requests.Request()
391390

392-
# Get an ID token for the function
393-
id_token_credentials = (
394-
google.auth.transport.requests.IDTokenCredentials.from_credentials(
395-
credentials, target_audience=refresh_url
396-
)
397-
)
398-
399-
# Refresh the token
400-
id_token_credentials.refresh(Request())
391+
# Get an identity token for the target URL
392+
id_token = google.auth.id_token.fetch_id_token(auth_req, refresh_url)
401393

402-
# Make the authenticated request
394+
# Make the HTTP request with the ID token
403395
response = requests.get(
404-
refresh_url, headers={"Authorization": f"Bearer {id_token_credentials.token}"}
396+
refresh_url, headers={"Authorization": f"Bearer {id_token}"}
405397
)
406398

407399
response.raise_for_status()

0 commit comments

Comments
 (0)