From c0a590dcc794e1f9fb1858cfa0b92d41d00089c3 Mon Sep 17 00:00:00 2001 From: Ehsan Karamad Date: Wed, 21 Jul 2021 13:13:22 -0400 Subject: [PATCH] feat: Set `audience` field in authenticated HTTP task example (#138) * Add explicit `audience1 field Unset `audience` will be take the URL as default value. When there are query and fragment parts, this would lead to authentication errors (401). * Add explicit `audience1 field feat: Set `audience` in authenticated HTTP task Unset `audience` will be take the URL as default value. When there are query and fragment parts, this would lead to authentication errors (401). * feat: Add explicit `audience1 field Unset `audience` will be take the URL as default value. When there are query and fragment parts, this would lead to authentication errors (401). --- cloud-tasks/snippets/create_http_task_with_token.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cloud-tasks/snippets/create_http_task_with_token.py b/cloud-tasks/snippets/create_http_task_with_token.py index 6f6909866d56..f09e85382bec 100644 --- a/cloud-tasks/snippets/create_http_task_with_token.py +++ b/cloud-tasks/snippets/create_http_task_with_token.py @@ -21,6 +21,7 @@ def create_http_task( location, url, service_account_email, + audience=None, payload=None, ): # [START cloud_tasks_create_http_task_with_token] @@ -35,7 +36,8 @@ def create_http_task( # project = 'my-project-id' # queue = 'my-queue' # location = 'us-central1' - # url = 'https://example.com/task_handler' + # url = 'https://example.com/task_handler?param=value' + # audience = 'https://example.com/task_handler' # service_account_email = 'service-account@my-project-id.iam.gserviceaccount.com'; # payload = 'hello' @@ -47,7 +49,7 @@ def create_http_task( "http_request": { # Specify the type of request. "http_method": tasks_v2.HttpMethod.POST, "url": url, # The full url path that the task will be sent to. - "oidc_token": {"service_account_email": service_account_email}, + "oidc_token": {"service_account_email": service_account_email, "audience": audience}, } }