From 7a5a0c6ca5372035521d5366373054a7ba95f2bd 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). --- samples/snippets/create_http_task_with_token.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/samples/snippets/create_http_task_with_token.py b/samples/snippets/create_http_task_with_token.py index 6f690986..f09e8538 100644 --- a/samples/snippets/create_http_task_with_token.py +++ b/samples/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}, } }