ClientException "failed to parse header value" when using Googleapis_auth package with flutter
I believe that you are getting 401 Unauthorized: "Failed to parse header value"
exception.
In order to invoke a restricted http Cloud Functions, the service account need the cloudfunctions.functions.invoke
permission which can be granted with the role roles/cloudfunctions.invoker
. Please confirm this.
https://cloud.google.com/functions/docs/reference/iam/roles
SetNameHere
Updated on December 21, 2022Comments
-
SetNameHere over 1 year
I'm trying to develop a flutter (web) application which needs to invoke access restricted http triggered cloud functions.
Therefore I have created a service account in my google cloud console and followed the example on how to retrieve an authenticated http client as an autonomous application of the googleapis_auth package (https://github.com/dart-lang/googleapis_auth).
final accountCredentials = new ServiceAccountCredentials.fromJson(r'''{ "private_key_id": "****", "private_key": "****", "client_email": "****.iam.gserviceaccount.com", "client_id": "****", "type": "service_account" }'''); var scopes = [CloudfunctionsApi.CloudPlatformScope]; AuthClient client = await clientViaServiceAccount(accountCredentials, scopes);
This seems to work fine. But when I try to use the received client to make a post request to my cloud function, I get a ClientException ("failed to parse header value").
http.Response resp = await client.post( CloudFunctiontriggerURL, body: {'data': userId});
As I understand the examples, this should work fine without specifying any headers manually in the POST function call. Correct? However, even if I specify the header manually, I get this error.
Any help with this would be highly appreciated.
-
SetNameHere almost 4 yearsthanks for your response. But yes I have granted the "Cloud Functions-Invoker" role to the used service account.
-
SetNameHere almost 4 yearsplease see edit. I hope it helps and it is what you meant.
-
Juancki almost 4 yearsNo, this wasn't. I mean't the full error that is alongside
Failed to parse header value
-
SetNameHere almost 4 yearsOkay sorry. Could you tell me how to retrieve the required information? I have never needed this before and therefore I am still quite inexperienced with this.
-
Juancki almost 4 yearsI would suggest you to contact the Google Cloud Platform Support, with the project id and cloud function name that you need help with. cloud.google.com/support-hub
-
SetNameHere almost 4 yearsSo I've talked to one of your collegues. On GCP side, it all seems to be configured correctly. Issue should be within flutter code.