Skip to content

Commit

Permalink
feat: Set audience field in authenticated HTTP task example (#138)
Browse files Browse the repository at this point in the history
* 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).
  • Loading branch information
ehsan-karamad authored and dandhlee committed Nov 15, 2022
1 parent dd23c5c commit eba50be
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cloud-tasks/snippets/create_http_task_with_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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 = '[email protected]';
# payload = 'hello'

Expand All @@ -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},
}
}

Expand Down

0 comments on commit eba50be

Please sign in to comment.