I have a cloud function named rad_format_text_v0
. I (andy@onehot.io) have permission to invoke it, shown here:
$ gcloud beta functions get-iam-policy rad_format_text_v0
bindings:
- members:
- allAuthenticatedUsers
- user:andy@onehot.io
role: roles/cloudfunctions.invoker
etag: BwWOSfjYxp0=
version: 1
I can invoke it using gcloud functions call
...
$ gcloud auth list
Credentialed Accounts
ACTIVE ACCOUNT
* andy@onehot.io
$ gcloud functions call rad_format_text_v0 --data "$(< test.json)"
executionId: 2wm7nrgc0vjo
result: |
["REDACTED successful result"]
However, when I try another HTTP client like curl
, it fails even though I'm passing an auth token...
$ curl -i -X POST "https://us-central1-onehot-autocoder.cloudfunctions.net/rad_format_text_v0" -H "Content-Type:application/json" -H "Authorization: bearer $(gcloud auth application-default print-access-token)" --data @test.json
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer error="invalid_token" error_description="The access token could not be verified"
Date: Mon, 22 Jul 2019 19:46:59 GMT
Content-Type: text/html; charset=UTF-8
Server: Google Frontend
Content-Length: 312
Alt-Svc: quic=":443"; ma=2592000; v="46,43,39"
<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unauthorized</h1>
<h2>Your client does not have permission to the requested URL <code>/rad_format_text_v0</code>.</h2>
<h2></h2>
</body></html>
I did exactly as explained in the documentation. I have no idea why my token is not working.